I am trying to launch a Java application in the background from Perl using the system command and capture the return code as a failure when the java command fails to launch the application. In the example below the bogus.jar file does not exist.
my $cmd = 'java -jar bogus.jar > bogus.log 2>&1 &';
system($cmd) == 0 or die "Failed to run command: [$cmd]\n";
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;
}