I'm trying to capture the exit status of a spawned process. The script conf.pl executes and I inserted a fault, so when all is well it returns 0 and with fault it returns 13
$? returns 0 even it there is a fault. Any thoughts?
use Run;
my $cfg_test = "conf_ini";
my $cfg_stat = "fresh";
my $system_call = '/test/conf.pl';
$pid = spawn $system_call, $cfg_test, $cfg_stat or die "spawn: $!";
push @pids, $pid;
my $num_proc1 = @pids;
while ($num_proc1) {
for ( my $i=0; $i< @pids; $i++) {
waitpid($pids[$i],0);
$num_proc1 --;
$pid --;
}
print "DOES THIS -- $? -- CAPTURE ANYTHING\n";
if ( $system_call >> 8, 0, 'Normal exit' ){
print "good\n";}
if( $exit >> 8, 42, 'Non-zero exit' ){
print "bad\n";}
if ($? == 13) {
print "failed: $!\n";
}
elsif ($? & 127) {
print "$pid died with signal $?\n",
($? & 127), ($? & 128) ? 'with' : 'without';
}
elsif ($? > 0) {
print "$pid died with signal $?\n";
}
else {
print "$pid exited with value $?\n", $? >> 8;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.