in reply to open-coding a system() operation
In the specific example here, we're using system to run java programs which read from data files given as parameters and produce log output on STDOUT, with exceptional output (such as an uncaught runtime exception that produces a stacktrace) going to STDERR. Because java plays games with its signal handlers, we discovered that running the driver perl script under "nohup" did not in fact allow us to start the driver script up and let it run in the background - java would still abort when the initial xterm was closed. Rewriting system() to include the setsid call finally fixed that problem.# my $status = system($command); # Our better version of system() my $status; my $pid = open(KID_STDIN, "|-"); if (not defined $pid) { die "cannot fork: $!; bailing out"; } if ($pid) { ## parent close(KID_STDIN); $status = $?; } else { POSIX::setsid(); # disconnect from controlling terminal open(STDOUT, ">> $_LogFileName"); open(STDERR, '>&STDOUT'); exec($command); }
|
|---|