Subject: Re: Novice question about piping
From: [email-masked] (Roy Johnson)
Date: Tue, 20 Apr 1993 16:12:16 GMT
Newsgroups: comp.lang.perl

[email-masked] (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