Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

by ikegami (Patriarch)
on Jan 20, 2014 at 20:11 UTC ( [id://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";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-19 03:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found