Subject: | Patch to fix error reporting if command killed by signal |
Currently if the command is killed by a signal, IPC::Cmd gives an error message containing '%d' and '%s' instead of the information.
% perl -MIPC::Cmd -E '($ok, $err) = IPC::Cmd::run(command => [ qw(perl -E dump) ]); say $err'
'perl -E dump' died with signal %d, %s coredump
This is because the error string contains printf() style placeholders, which are not understood by loc(), the function used to generate localized error messages. Fix it like this:
diff -ru IPC-Cmd-0.85_02/lib/IPC/Cmd.pm IPC-Cmd-0.85_02-new/lib/IPC/Cmd.pm
--- IPC-Cmd-0.85_02/lib/IPC/Cmd.pm 2013-10-10 14:04:59.000000000 +0100
+++ IPC-Cmd-0.85_02-new/lib/IPC/Cmd.pm 2013-10-25 10:57:41.264283664 +0100
@@ -1849,7 +1849,7 @@
} elsif ( $ce & 127 ) {
### some signal
- $str = loc( "'%1' died with signal %d, %s coredump\n",
+ $str = loc( "'%1' died with signal %2, %3 coredump",
$pp_cmd, ($ce & 127), ($ce & 128) ? 'with' : 'without');
} else {
With this fix, the correct error is given:
% perl -MIPC::Cmd -E '($ok, $err) = IPC::Cmd::run(command => [ qw(perl -E dump) ]); say $err'
'perl -E dump' died with signal 6, with coredump