I suggest checking the $? variable (a.k.a. $CHILD_ERROR is you use English; pun intended). This allows for a more thorough inspection of how your system() call turns out.
The thing to understand is that $? is a 16-bit word (art credit to @ikegami):
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| 15| 14| 13| 12| 11| 10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0|
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
\-----------------------------/ \-/ \-------------------------/
Exit code core Signal that killed
(0..255) dumped (0..127)
(0..1)
system($runCmd);
if ($? == -1) { # Failed to start program / error of the wait(2) system call
die "Failed to execute '$runCmd': $!";
} elsif ($? & 127) { # Check for non-zero signal
die "'$runCmd' died with signal", ($? & 127), ($? & 128) ? 'with' : 'without', " coredump";
} else { # No kill signal, check exit code.
my $exit_code = $? >> 8; # This is the number you said to be 255.
# print "'$runCmd' exited with value ", $exit_code, "\n";
if ($exit_code == 255) {
die("Failed to run \"$runCmd\": $!");
} else {
# can do additional checks for other exit codes if desired
}
exit $exit_code;
}
There is a noteworthy "alternative" if you really don't want to mess with $?. Basically, just use IPC::System::Simple. Note that it isn't a core module, so you need to install it.
Using it is simple:
use IPC::System::Simple qw(system); # system() will now die properly
my $exit_value = system($runCmd);
my $exit_value2 = system($runCmd,@args); # Alternative form that avoids shell if @args
If you don't want to override system you could use run instead:
use IPC::System::Simple qw(run);
my $exit_value = run($runCmd);
my $exit_value2 = run($runCmd,@args);