From 4ef107a6cabd33854b770659cca90f12a2326104 Mon Sep 17 00:00:00 2001 From: Dave Mitchell Date: Tue, 16 Sep 2003 22:56:20 +0100 Subject: [PATCH] [DOC PATCH] Re: [perl #23779] $? and negative exit codes Message-ID: <20030916205620.GB1246@fdgroup.com> p4raw-id: //depot/perl@21253 --- pod/perlfunc.pod | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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. -- 2.7.4