set the stdin & stdout for an external program

G

Guest

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
 
G

Gianni Mariani

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

Maxim Yegorushkin

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.com/listings/chapter-5/dup2.c
 
G

Guest

Maybe I ask something OS depended but maybe not. So I ask:
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.com/listings/chapter-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).
 
M

Maxim Yegorushkin

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

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,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top