C/C++ library to access a process's stdin and stdout?

X

xman

I'm looking for a C/C++ library that can get access to the stdin and
stdout of a process. I may invoke a external program in a C/C++
program, but how do write data into the stdin of the external program,
and read data out from the stdout of the external program?

Suggestions are much appreciated.
 
G

Gianni Mariani

I'm looking for a C/C++ library that can get access to the stdin and
stdout of a process. I may invoke a external program in a C/C++
program, but how do write data into the stdin of the external program,
and read data out from the stdout of the external program?

Suggestions are much appreciated.

Is the external program already running or does your program start the
external program.

In general there is no C++ standard (and so off topic here) way to do
what you ask but Linux/Unix machines use "popen" and I think Win32 has
a similar _popen function.
http://msdn2.microsoft.com/en-us/library/96ayss4b(VS.80).aspx

Any further questions should be directed to a more relevant news
group.
 
R

Ron AF Greve

Hi,

Using unix/linux you can do this by closing 0 (input) and 1 (output)
close(0) close(1) in combination with pipe. Then fork another process
(which inherits its parents file descriptors and use the other and of the
pipe created. Sincd file desciptors are assigned beginning with the lowest
available stdin and stdout will be assigned to the pipe.


Regards, Ron AF Greve

http://www.InformationSuperHighway.eu
 
M

Michael DOUBEZ

xman a écrit :
I'm looking for a C/C++ library that can get access to the stdin and
stdout of a process. I may invoke a external program in a C/C++
program, but how do write data into the stdin of the external program,
and read data out from the stdout of the external program?

Suggestions are much appreciated.

I have used pstream with success. It is basically a wrapper around
popen/pclose.

See: http://pstreams.sourceforge.net/

Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top