469,592 Members | 1,914 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

set the stdin & stdout for an external program

Maybe I ask something OS depended but maybe not. So I ask:
I want to run an external program from my C++ program.
I want stdin of external program constructed from a C++ string in my
program.
I want stdout of external program constructs a C++ string in my program.

Is this possible without intermediate temporary files?

Its OT but if you know an OS depended call (for Win32 or Linux) can you
give it to me?
Sorry for my bad english and THANKS
Aug 28 '05 #1
5 8677
<- Chameleon -> wrote:
Maybe I ask something OS depended but maybe not. So I ask:
I want to run an external program from my C++ program.
I want stdin of external program constructed from a C++ string in my
program.
I want stdout of external program constructs a C++ string in my program.

Is this possible without intermediate temporary files?
Yes. It is system specific and off topic here.

Its OT but if you know an OS depended call (for Win32 or Linux) can you
give it to me?


For Linux, you can use somthing like popen, however I'd probably do
somthing different. I'd probably call the system calls directly to
avoid the buffering through a FILE *.

For Windoes, "_popen" does exist.
Aug 28 '05 #2

<- Chameleon -> wrote:
Maybe I ask something OS depended but maybe not. So I ask:
I want to run an external program from my C++ program.
I want stdin of external program constructed from a C++ string in my
program.
I want stdout of external program constructs a C++ string in my program.

Is this possible without intermediate temporary files?

Its OT but if you know an OS depended call (for Win32 or Linux) can you
give it to me?


If you want a one-way communication, that is when the parent process
only writes and the child only reads or vice versa, use popen. If you
want a two-way communication open two pipes in the parent process, fork
a child, replace STDIN_FILENO and STDOUT_FILENO (and probably
STDERR_FILENO) file descriptors with read and write ends of the two
pipes.

Here is example how it is done with STDIN_FILENO.
http://www.advancedlinuxprogramming....apter-5/dup2.c

Aug 29 '05 #3
>>Maybe I ask something OS depended but maybe not. So I ask:


I want to run an external program from my C++ program.
I want stdin of external program constructed from a C++ string in my
program.
I want stdout of external program constructs a C++ string in my program.

Is this possible without intermediate temporary files?

Its OT but if you know an OS depended call (for Win32 or Linux) can you
give it to me?

If you want a one-way communication, that is when the parent process
only writes and the child only reads or vice versa, use popen. If you
want a two-way communication open two pipes in the parent process, fork
a child, replace STDIN_FILENO and STDOUT_FILENO (and probably
STDERR_FILENO) file descriptors with read and write ends of the two
pipes.

Here is example how it is done with STDIN_FILENO.
http://www.advancedlinuxprogramming....apter-5/dup2.c


thanks but the problem is that the child process is in binary form. I
cannot change it.
I can change only my program (caller).
Aug 29 '05 #4

<- Chameleon -> wrote:

[]
thanks but the problem is that the child process is in binary form. I
cannot change it.


You don't need to change the child program. fork() in the parent
process, set up the file descriptors and exec("the child process is in
binary form", ...) in the child process.

Aug 29 '05 #5
This is done in the parent process.
PC: http://209.171.52.99/threads/process...asp?print=true
Linux: same concepts, different calls. e.g. see book Linux Socket
Programming.
I think google searches should get you what you need.

Stuart

Aug 29 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Sanyi Benczik | last post: by
reply views Thread by lickspittle | last post: by
8 posts views Thread by max(01)* | last post: by
6 posts views Thread by Andrew | last post: by
4 posts views Thread by Lad | last post: by
7 posts views Thread by Benjamin Watine | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.