Path: utzoo!utgpu!watserv1!watmath!att!rutgers!ucsd!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.lang.perl Subject: Re: problem redirecting STDOUT to pipe Message-ID: <1990Jul16.000030.16729@iwarp.intel.com> Date: 16 Jul 90 00:00:30 GMT References: <1123@etnibsd.UUCP> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 38 In-Reply-To: vsh@etnibsd.UUCP (Steve Harris) In article <1123@etnibsd.UUCP>, vsh@etnibsd (Steve Harris) writes: | print STDERR "before: fileno(STDOUT) = ", fileno(STDOUT), "\n"; | open(STDOUT, ">foo"); | print STDERR "after: fileno(STDOUT) = ", fileno(STDOUT), "\n"; | result: | before: fileno(STDOUT) = 1 | after: fileno(STDOUT) = 1 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- | 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 short answer, which may lead you to more insight, is that you also need to think of the stdout of the "dd" command. The stdin fd of the dd command (which you are asking to be the stdout of the parent) cannot be the same as the stdout fd of dd. Therefore, in order for the dd to have a proper stdout (fd 1), the parent's stdout fd gets trashed after all the piping and forking. (Or something like that. It's too hot to think here... we native Oregonians are just not used to 85-degree weather for almost a whole week in a row now. Especially on a weekend. Yuck. I may actually have to buy an air-conditioner for my house because of this stupid greenhouse effect. :-) print "Just another Perl hacker, with time enough to read only the first part of articles, :-)" -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/