home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!ferkel.ucsb.edu!piggy!chupchup
- From: chupchup@ferkel.ucsb.edu (Robert Earl)
- Subject: Re: need help reading from a child
- Message-ID: <chupchup.714463805@piggy>
- Organization: (EVIL!)
- References: <1992Aug21.202934.3736@mercury.unt.edu>
- Date: Sat, 22 Aug 1992 06:10:05 GMT
- Lines: 33
-
- gene@ponder.csci.unt.edu (Gene De Lisa) writes:
-
- | This code hangs on the read (or fread).
-
- | if (pipe(pipefds) < 0) {
- | perror("pipe");
- | return(NULL);
- | }
-
- [ code deleted... ]
-
- | dup2(pipefds[0],0);
- | dup2(pipefds[1],1);
- | dup2(pipefds[1],2);
-
- What you're doing here is setting up a loop: the same process that
- writes to its stdout/err is going to read what it just wrote on stdin,
- because writes to pipefds[1] come out on reads on pipefds[0].
-
- You need to close pipefds[0] in the child and dup2() pipefds[1] onto
- the desired fds. Close pipefds[1] in the parent, then read from
- pipefds[0].
-
- If you actually want to write stuff to the child's stdin, make another
- call to pipe() and close the uneeded descriptors in each process. All
- the usual warnings about potential deadlocks apply. To do this right
- you would need to use ptys or something similar - see the FAQ. (Or
- was that just the comp.lang.perl FAQ?)
- --
- "If you've got a pig that likes jumping fences, | robert earl
- you have to make its fence a lot higher all at | rearl@ucsd.edu
- once -- if you do it by increments, all you're | rearl@piggy.ucsb.edu
- doing is training a jumping pig." -Henry Spencer|
-