Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: Getting a return code from waitpid in Windows

by ikegami (Pope)
on Jan 20, 2014 at 20:11 UTC ( #1071376=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Getting a return code from waitpid in Windows
in thread Getting a return code from waitpid in Windows

You call waitpid after you've reaped the process, causing causing an error ($? = -1;, error message in $!).

You gotta check $? after the successful call to waitpid.

use POSIX qw( WNOHANG ); my $pid = system(1,'perl -e"sleep(4); exit(5);"'); while (1) { my $wait = waitpid($pid, WNOHANG); die $! if $wait < 0; last if $wait > 0; } print "Command completed with exit code $?.\n";

I presume you actually do something else in the loop? If not, there's no reason to use WHOHANG.

my $pid = system(1,'perl -e"sleep(4); exit(5);"'); waitpid($pid, 0); die $! if $? < 0; print "Command completed with exit code $?.\n";


Comment on Re^3: Getting a return code from waitpid in Windows
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1071376]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (14)
As of 2014-07-22 15:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (117 votes), past polls