Managing stdin and stdout of new processes

Managing stdin and stdout of new processes

Post by Kevin Woodwa » Thu, 05 Aug 1999 04:00:00



Hi All,

I wish to send the contents of unsigned char array to the stdin of
program and store the programs stdout in another unsigned char array
without using temp files. The data maynot be NULL terminated. I'm
using Linux and EGCS.

Any ideas? I assume I should using popen, but none of my ref. manuals
cover popen... This is only intended to be a stopgap measure until
native support is added.

Thanks,

Kevin Woodward.

 
 
 

Managing stdin and stdout of new processes

Post by David Schwart » Fri, 10 Sep 1999 04:00:00


        man pipe
        man fork
        man exec

        You need two pipes, one to stuff input into the program and one to take
output from it. So basically you do the following:

        1) Create the two pipes.

        2) Call 'fork'

        3) In the child, close the half of each pipe you're not using and then
'exec' the program you want to run.

        4) In the parent, close the half of each pipe you're not using. Then
send the data to the child. Read the child's output from the output
pipe.

        5) If you can't tell from the output when the child is done, catch
SIGCHLD/SIGPIPE. They'll tell you.

        6) Don't forget to call wait/waitpid so you don't leave a zombie
around.

        DS


> Hi All,

> I wish to send the contents of unsigned char array to the stdin of
> program and store the programs stdout in another unsigned char array
> without using temp files. The data maynot be NULL terminated. I'm
> using Linux and EGCS.

> Any ideas? I assume I should using popen, but none of my ref. manuals
> cover popen... This is only intended to be a stopgap measure until
> native support is added.

> Thanks,

> Kevin Woodward.


 
 
 

1. redirecting STDOUT of a bg process to STDOUT of a new xterm

I often start a background process in an xterm and then kill the xterm.
The
process is still running on the machine but it's tty is "?"

Is there a way to redirect this process so that it becomes a job on a
new
xterm?

I want to see what gets printed to STDOUT of this process.

Thanks.

--

**************************************************************
Mike Green                              Intel Corp

ph (602) 552-3428                       5000 W. Chandler Blvd.
fax (602) 554-6006                      Chandler, AZ  85226
**************************************************************
****************My opinions are strictly my own***************

2. Changing HD on IDE problem

3. sockets dup()ed to stdin and stdout of a process

4. How to stop telnet to a certain host

5. Controlling forked processes stdin/stdout

6. what happened to code fusion?

7. Using separate window child process for stdin/stdout

8. Missing history in bash 2.02 for Win NT.

9. HOW TO RE-DIRECT THE STDIN/STDOUT FOR A PROCESS RUNNING IN THE BACKGROUND

10. redirecting stdin & stdout of a running process

11. Taking over a child process's stdin/stdout

12. redirect stdin/stdout does not for the ftp client child process

13. Access to stdin/stdout of a child process