... close CMD; waitpid $pid, 0; print "$progname ended: status: ", $? >>8;
I'm a little surprised that you get the correct status value here, because close already does wait for the subprocess at the other end of the pipe (so the waitpid is neither needed nor setting the $? correctly). At least on Unix. Does this behave differently on Windows?
#!/usr/bin/perl -l my $cmd = q(perl -e 'chomp(my $ret = <STDIN>); exit $ret+1'); my $pid = open CMD, '|-', $cmd or die $!; print CMD 98; close CMD; print "status from close: ", $? >> 8; waitpid $pid, 0; print "status from waitpid: ", $? >> 8; __END__ $ ./839409.pl status from close: 99 status from waitpid: 72057594037927935
In reply to Re^2: "Answer" questions in an interactive program?
by almut
in thread "Answer" questions in an interactive program?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |