home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!usenet.coe.montana.edu!news.u.washington.edu!stein.u.washington.edu!wiml
- From: wiml@stein.u.washington.edu (William Lewis)
- Newsgroups: comp.lang.perl
- Subject: Re: fork and STDOUT
- Date: 31 Dec 1992 04:39:07 GMT
- Organization: University of Washington
- Lines: 31
- Message-ID: <1htthbINNqg9@shelley.u.washington.edu>
- References: <1992Dec30.223911.16297@rchland.ibm.com>
- NNTP-Posting-Host: stein.u.washington.edu
-
- essbaum@rchland.vnet.ibm.com (Alexander Essbaum) writes:
- >if (!($pid = fork)) {
- > open (cmd,"$cmd|"); # $cmd is a call to another perl script
- > print <cmd>;
- > exit 0;
- >}
-
- >the stuff returned in <cmd> (which comes from print "..."; and `...`; lines
- >in $cmd) doesn't print properly. it seems to be getting buffered such that
- >when $cmd exits, all of STDERR gets printed, then all of STDOUT.
-
- Generally, stder doesn't get redirected along with stdout. (That's
- its purpose for being separate.) I'd guess that the error output is
- going straight to your tty when $cmd runs, but stdout is getting trapped
- in the pipe. Then you print the pipe's contents on the next line. So
- all the error output will precede the normal output.
-
-
- >open (something,">&STDOUT");
-
- >can someone explain exactly what this does (what is "duping"?) or maybe
- >point me where to look (i checked the FAQ)?
-
- The dup() call (in unix) takes a file descriptor and returns another
- file decriptor which references the same file (or tty or socket or
- whatever). The dup2() call does the same thing, except you can specify
- which file descriptor you want it to return. So if you specify stdout,
- then stdout will start behaving just like whatever fd it was you duplicated
- into it. (This is how you redirect output into a file, for example.)
- I'm not sure if I'm being entirely clear here, but the Unix man pages for
- dup() and dup2() are the place to look.
-