By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,181 Members | 1,169 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,181 IT Pros & Developers. It's quick & easy.

set the stdin & stdout for an external program

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
<- 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

P: n/a

<- 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

P: n/a
>>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

P: n/a

<- 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

P: n/a
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.