Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!seismo!lll-lcc!ptsfa!cogent!mark
From: mark@cogent.UUCP (Mark Steven Jeghers)
Newsgroups: comp.unix.questions,comp.unix.wizards
Subject: Running stdin/out through a pipe to a child process
Message-ID: <136@cogent.UUCP>
Date: Mon, 12-Jan-87 02:14:42 EST
Article-I.D.: cogent.136
Posted: Mon Jan 12 02:14:42 1987
Date-Received: Mon, 12-Jan-87 06:38:13 EST
Reply-To: mark@cogent.UUCP (Mark Steven Jeghers)
Distribution: world
Organization: Cogent Software Solutions, Stockton, CA
Lines: 39
Keywords: popen, fork, exec, pipes, stdio, arrrrgh!
Xref: mnetor comp.unix.questions:613 comp.unix.wizards:565

I need to know how I might create a child process with 2 pipes connected to
it, one with which the parent process feeds a stream to the childs stdin, 
and one from which the parent reads a stream from the childs stdout.  I 
understand how to use popen() to connect either stdin OR stdout between
processes, but I need to have BOTH.  The following picture demonstrates:

                      +-------------------+
                      |                   |
                      |  Parent Process   |
                      |                   |
                      +-------------------+
               Pipe that   |         ^ Pipe that
               feeds stdin V         | reads stdout
                      +-------------------+
                      |                   |
                      |   Child Process   |
                      |                   |
                      |   (could be a     |
                      |    filter like    |
                      |    sed or cat,    |
                      |    or a shell)    |
                      |                   |
                      +-------------------+

I imagine that I could probably use fork() for this, that is, I could
have all the pipes I wanted between the processes then.  But, after getting
the child process to exec() into the program I want there (like sed, cat, or
sh) how would I get those pipes to be hooked up to the child processes stdin
and stdout?
-- 
+----------------------------------------------------------------------------+
|     Mark Steven Jeghers         ECHOMPGULP - process has eaten it          |
| cryptography, terrorist, DES, drugs, cipher, secret, decode, NSA, CIA, NRO |
|                                                                            |
|     {ihnp4,cbosgd,lll-lcc,lll-crg}|{dual,ptsfa}!cogent!mark                |
|                                                                            |
| Cogent Software Solutions can not be held responsible for anything said    |
| by the above person since they have no control over him in the first place |
+----------------------------------------------------------------------------+