home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / perl / 4972 < prev    next >
Encoding:
Text File  |  1992-07-27  |  1.3 KB  |  60 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!mcsun!Germany.EU.net!news.netmbx.de!zrz.tu-berlin.de!math.fu-berlin.de!Sirius.dfn.de!chx400!bernina!neptune!weingart
  3. From: weingart@inf.ethz.ch (Tobias Weingartner)
  4. Subject: Pipe, et al, what am I doing wrong?
  5. Message-ID: <1992Jul27.115715.21337@neptune.inf.ethz.ch>
  6. Followup-To: comp.lang.perl
  7. Keywords: pipe, fork
  8. Sender: news@neptune.inf.ethz.ch (Mr News)
  9. Nntp-Posting-Host: tau.inf.ethz.ch
  10. Reply-To: weingart@inf.ethz.ch
  11. Organization: ETH - Switzerland
  12. Date: Mon, 27 Jul 1992 11:57:15 GMT
  13. Lines: 45
  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.  
  21. #!/usr/local/bin/perl
  22. #
  23. # To test fork, pipe
  24. # and other things.
  25.  
  26. select(STDIN); $| = 1;
  27. select(STDERR); $| = 1;
  28. select(STDOUT); $| = 1;
  29.  
  30. pipe( READH, WRITEH );
  31. $pid = fork();
  32. die "Could not fork.\n" if( ! defined($pid) );
  33.  
  34. @data = ();
  35. if( $pid == 0 ){
  36.     open(STDOUT, ">&WRITEH");
  37.     open(STDERR, ">&WRITEH");
  38.     exec( '/bin/cat', '/etc/passwd' );
  39. }else{
  40.     open(STDIN, "<&READH");
  41.     while( <STDIN> ){
  42.         push(@data, $_);
  43.         print ".";
  44.     }
  45.     print "\nLines: $#data\n";
  46. }
  47.  
  48. exit(0);
  49.  
  50. #
  51. # End of script.
  52.  
  53.  
  54. Can anyone give me a working example of this?
  55.  
  56. TNX in advance!
  57.  
  58. --Toby.
  59.  
  60.