Article: 2278 of comp.lang.perl
Xref: feenix.metronet.com comp.lang.perl:2278
Newsgroups: comp.lang.perl
Path: feenix.metronet.com!news.utdallas.edu!tamsun.tamu.edu!cs.utexas.edu!zaphod.mps.ohio-state.edu!howland.reston.ans.net!bogus.sura.net!udel!news.intercon.com!psinntp!shellgate!shell!rjohnson
From:
[email protected] (Roy Johnson)
Subject: Re: Novice question about piping
In-Reply-To:
[email protected]'s message of Fri, 16 Apr 1993 21:03:56 GMT
Message-ID: <
[email protected]>
Sender:
[email protected] (USENET News System)
Organization: Houston, TX
References: <
[email protected]>
Date: Tue, 20 Apr 1993 16:12:16 GMT
Lines: 31
[email protected] (MA.Mostow;333123) writes:
I want my Perl program to generate a number of lines of output,
pipe them to a command, and store the standard output of that command
in a Perl variable. Using filehandles I would seem to need:
open(FIL, "| command |")
This works nicely.
#!/usr/local/bin/perl
pipe(RH, WH);
if (fork()) {
#Parent
close(WH);
# Read desired result from RH
while($_=<RH>) {
print;
}
} else {
#Child
close(RH);
open(STDOUT, ">&WH"); #Make STDOUT go to RH;
open(OUT, "|wc");
# Write data to OUT
print(OUT "Do the hoochy-coochy\nline 2\nline 3");
close(OUT);
exit 0;
}
--
Roy Johnson Shell Development Company (but speaking for myself)
"Nothing says 'I love my country' like higher taxes." -- Ed Ipser