469,594 Members | 2,145 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,594 developers. It's quick & easy.

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

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.

May 13 '07 #1
4 10947
On May 13, 10:02 pm, xman <cshin...@gmail.comwrote:
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/lib...4b(VS.80).aspx

Any further questions should be directed to a more relevant news
group.
May 13 '07 #2
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

"xman" <cs******@gmail.comwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
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.

May 13 '07 #3


In additon, a little googling for pipe, close, open gives:

http://www.cs.sunysb.edu/~cse533/asgn1/pipes.html

Regards, Ron AF Greve

http://www.InformationSuperHighway.eu

"Ron AF Greve" <ron@localhostwrote in message
news:46*********************@news.xs4all.nl...
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

"xman" <cs******@gmail.comwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
>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.


May 13 '07 #4
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
May 14 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

18 posts views Thread by jas | last post: by
6 posts views Thread by ccdrbrg | last post: by
2 posts views Thread by Greg Ercolano | last post: by
12 posts views Thread by bhunter | last post: by
4 posts views Thread by rdabane | last post: by
reply views Thread by Gabriel Genellina | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.