home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / perl / 4981 < prev    next >
Encoding:
Internet Message Format  |  1992-07-27  |  1.2 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!sample.eng.ohio-state.edu!purdue!mentor.cc.purdue.edu!noose.ecn.purdue.edu!lucky.ecn.purdue.edu!newlin
  2. From: newlin@lucky.ecn.purdue.edu (Johnny N.)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: Pipe, et al, what am I doing wrong?
  5. Keywords: pipe, fork
  6. Message-ID: <newlin.712265408@lucky.ecn.purdue.edu>
  7. Date: 27 Jul 92 19:30:08 GMT
  8. References: <1992Jul27.115715.21337@neptune.inf.ethz.ch>
  9. Sender: news@noose.ecn.purdue.edu (USENET news)
  10. Organization: Purdue University Engineering Computer Network
  11. Lines: 33
  12.  
  13. weingart@inf.ethz.ch (Tobias Weingartner) writes:
  14.  
  15. >Here is a small script, that seems to hang.  What am I doing
  16. >wrong?  A ps shows that the child is waiting for the parent
  17. >to `wait` on it.  Also, the parent seems to hang because it
  18. >does not get EOF.
  19.  
  20. >Can anyone give me a working example of this?
  21.  
  22.   sure.
  23.  
  24. --------- original script deleted -------------
  25. try this:
  26.  
  27. #!/usr/local/bin/perl
  28.  
  29. @data= ();
  30.  
  31. die "can't fork: $!" unless defined ($pid=open (CHILD, "-|"));
  32. if ($pid == 0) {
  33.         exec ('/bin/cat/', '/etc/passwd');
  34. }
  35. else {
  36.         open (STDIN, "<&CHILD");
  37.         while (<STDIN>) {
  38.                 push (@data, $_);
  39.                 print ".";
  40.         }
  41.         print "\nLines: $#data\n";
  42. }
  43.  
  44.  
  45. -John
  46.