From: Dave Mitchell Date: Tue, 16 Sep 2003 21:56:20 +0000 (+0100) Subject: [DOC PATCH] Re: [perl #23779] $? and negative exit codes X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4ef107a6cabd33854b770659cca90f12a2326104;p=p5sagit%2Fp5-mst-13.2.git [DOC PATCH] Re: [perl #23779] $? and negative exit codes Message-ID: <20030916205620.GB1246@fdgroup.com> p4raw-id: //depot/perl@21253 --- diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index d7a3fa4..fff672b 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -5745,9 +5745,17 @@ your program. You can check all the failure possibilities by inspecting C<$?> like this: - $exit_value = $? >> 8; - $signal_num = $? & 127; - $dumped_core = $? & 128; + if ($? == -1) { + print "failed to execute: $!\n"; + } + elsif ($? & 127) { + printf "child died with signal %d, %s coredump\n", + ($? & 127), ($? & 128) ? 'with' : 'without'; + } + else { + printf "child exited with value %d\n", $? >> 8; + } + or more portably by using the W*() calls of the POSIX extension; see L for more information.