4 use Getopt
::Long qw
/:config no_ignore_case permute/;
6 use IPC
::Run qw
/start finish/;
8 $0 = "reportcmdstatus";
14 's|report-start!' => \
$report_start,
15 'c|clone!' => \
$clone_status,
16 'help|?' => sub{ pod2usage
(-exitval
=>0, -verbose
=>99); },
17 '<>' => sub{ unshift @ARGV, @_; die '!FINISH'; },
18 ) or pod2usage
(-exitval
=>2, -verbose
=>99);
22 eval q{ use String::ShellQuote; 1; } or die $@
;
23 $COMMAND_STRING_QUOTED = join(' ', map {String
::ShellQuote
::shell_quote
($_)} @ARGV);
26 sub child_process_forked
30 printf STDERR
"starting process %d: %s\n", $$, $COMMAND_STRING_QUOTED;
34 $ipc = start
[@ARGV], init
=>\
&child_process_forked
;
35 $COMMAND_PID = $ipc->{KIDS
}->[0]->{PID
};
39 if(WIFSIGNALED
($status))
41 printf STDERR
"command (pid $COMMAND_PID) terminated by signal: %d\n", WTERMSIG
($status);
42 $mystatus = 128 + WTERMSIG
($status);
46 printf STDERR
"command (pid $COMMAND_PID) exited with status: %d\n", WEXITSTATUS
($status);
47 $mystatus = WEXITSTATUS
($status);
50 exit $mystatus if $clone_status;
60 reportcmdstatus - Textually show how the given command finished (exit status/signal)
64 reportcmdstatus [I<OPTIONS>] [--] I<COMMAND> [I<ARGS>]
72 Take I<COMMAND>'s status and itself exits with it.
75 If I<COMMAND> did not exit normally, but it is terminated by a signal,
76 exit 128 + I<SIGNAL>, like most shells do.
78 =item -s, --report-start
80 Report what is being started, ie. I<COMMAND> I<ARGS>, to the STDERR.