home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- 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
- From: weingart@inf.ethz.ch (Tobias Weingartner)
- Subject: Pipe, et al, what am I doing wrong?
- Message-ID: <1992Jul27.115715.21337@neptune.inf.ethz.ch>
- Followup-To: comp.lang.perl
- Keywords: pipe, fork
- Sender: news@neptune.inf.ethz.ch (Mr News)
- Nntp-Posting-Host: tau.inf.ethz.ch
- Reply-To: weingart@inf.ethz.ch
- Organization: ETH - Switzerland
- Date: Mon, 27 Jul 1992 11:57:15 GMT
- Lines: 45
-
- Here is a small script, that seems to hang. What am I doing
- wrong? A ps shows that the child is waiting for the parent
- to `wait` on it. Also, the parent seems to hang because it
- does not get EOF.
-
-
- #!/usr/local/bin/perl
- #
- # To test fork, pipe
- # and other things.
-
- select(STDIN); $| = 1;
- select(STDERR); $| = 1;
- select(STDOUT); $| = 1;
-
- pipe( READH, WRITEH );
- $pid = fork();
- die "Could not fork.\n" if( ! defined($pid) );
-
- @data = ();
- if( $pid == 0 ){
- open(STDOUT, ">&WRITEH");
- open(STDERR, ">&WRITEH");
- exec( '/bin/cat', '/etc/passwd' );
- }else{
- open(STDIN, "<&READH");
- while( <STDIN> ){
- push(@data, $_);
- print ".";
- }
- print "\nLines: $#data\n";
- }
-
- exit(0);
-
- #
- # End of script.
-
-
- Can anyone give me a working example of this?
-
- TNX in advance!
-
- --Toby.
-
-