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!
In reply to wait versus close on a pipe by daven7
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |