Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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 lurking in the Monastery: (9)
As of 2015-07-31 11:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (276 votes), past polls