Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: problem redirecting STDOUT to pipe Message-ID: <8755@jpl-devvax.JPL.NASA.GOV> Date: 16 Jul 90 22:39:00 GMT References: <1123@etnibsd.UUCP> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 20 In article <1123@etnibsd.UUCP> vsh@etnibsd.UUCP (Steve Harris) writes: : Perlers, : print STDERR "before: fileno(STDOUT) = ", fileno(STDOUT), "\n"; : open(STDOUT, "| dd of=foo"); : print STDERR "after: fileno(STDOUT) = ", fileno(STDOUT), "\n"; : result: : before: fileno(STDOUT) = 1 : after: fileno(STDOUT) = 3 : : =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- : : In the first case, re-opening STDOUT preserves the original fileno, in : the second, it does not. Why? Is the way it should behave? The problem is that pipe() opens two file descriptors, the second one being the write descriptor. I've made the mypopen() routine detect this and dup the upper descriptor to the lower where necessary, so it'll be fixed in the next patch. Larry