daven7 has asked for the wisdom of the Perl Monks concerning the following question:
Since Perl lets me actually open these as pipes so I can read their output (instead of having the programs write a file) I thought I'd try it using Perl. I'm doing something like this (error checking removed for brevity):myprog1 & myprog2 & wait
Why does the close fail? The help for "close" indicates that an implicit wait is done on the piped process before the close returns -- does the same thing happen if an explicit "wait" is done first? If so, how does the reading of the pipes (i.e. <PIPE1> and <PIPE2>) work if the file has been closed? Does Perl maintain the output of the program somewhere? It seems weird that you can read from something that you can't close. Am I missing something here? Thanks.my $pid1 = open(PIPE1, "myprog1|"); my $pid2 = open(PIPE2, "myprog2|"); while ($pid1 >= 0 || $pid2 >= 0) { my $pid = wait; if ($pid == $pid1) { print "myprog1 completed.\n"; $pid1 = -1; } elsif ($pid == $pid2) { print "myprog2 completed.\n"; $pid2 = -1; } } my $output1 = <PIPE1>; # this works (I see the output of "myprog1") my $output2 = <PIPE2>; # this works as well close PIPE1; # this fails! close PIPE2; # this fails as well!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: wait versus close on a pipe
by kyle (Abbot) on Jun 03, 2008 at 02:42 UTC | |
by pc88mxer (Vicar) on Jun 03, 2008 at 03:55 UTC | |
by tye (Sage) on Jun 03, 2008 at 06:40 UTC | |
by kyle (Abbot) on Jun 03, 2008 at 04:14 UTC | |
|
Re: wait versus close on a pipe
by pc88mxer (Vicar) on Jun 03, 2008 at 03:40 UTC |