Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!spool.mu.edu!uwm.edu!linac!att!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal L. Schwartz) Newsgroups: comp.lang.perl Subject: Re: pager pipes Message-ID: <1991Feb17.024739.17286@iwarp.intel.com> Date: 17 Feb 91 02:47:39 GMT References: <1991Feb16.210445.7760@convex.com> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal L. Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 33 In-Reply-To: tchrist@convex.COM (Tom Christiansen) In article <1991Feb16.210445.7760@convex.com>, tchrist@convex (Tom Christiansen) writes: | I was trying to set up an automatic pager for STDOUT, and | it doesn't seem to work. If I choose a different handle, | it's fine. Any clues? | | $pager = $ENV{'PAGER'} || 'more'; | open(STDOUT, "| $pager") || die "can't reopen STDOUT to $pager: $!"; | open(STDERR, ">&PIPE") || die "dup failed: $!"; | system 'ps t'; | system 'grep nada nonesuch'; | while (<>) { print; } | close(STDOUT) || die "close failed: $!"; | | Notice that I never die of a bad dup even though there is no | PIPE handle. If you %s/STDOUT/PIPE/g and add an appropriate | select, it all works fine. This is under both 3.044 and 4.0beta. Arrrgh... Think about what $pager's stdout is at the time of the fork! This works: open(TMP,"| $pager"); # $pager's stdout is Perl's stdout open(STDOUT, ">&TMP"); # Perl's stdout is now the pager's stdin close(TMP); # no need for this anymore (The appropriate error checking is left as an exercise to the reader.) print "Just another Perl hacker," -- /=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: "Intel: putting the 'backward' in 'backward compatible'..."====/