Avraham Shapiro wrote:
> What I meant is the semantics of backticks indicate that an exception
> that occurrs in the command
> enclosed by backticks are propagated to the initiating process at the
> point of the backticks. If
> the java program unexpectedly dies with a fatal exception this will
> kill the PERL program too,
> unless an EVAL block encloses the backticks to provide exception
> handling.
This isn't true.
$ perl -e 'my $o = `perl -e "die;" 2>&1`; print "I got: $o"; print "Done.\n"'
I got: Died at -e line 1.
Done.
(What I'm doing there is running a perl inside of backticks with a one-line
script, "die;", redirecting stderr to stdout (2>&1), and printing the captured
output.)
If you were correct, I would never get to the "I got:" part of the output.
The only real way to discover the failure of a qx() or backticks is by looking
at $?, which contains the exit code, received signal (if any), and whether or
not there was a core dump. If you don't check $?, you can't differentiate
between errors, nonexistent programs, or successes without any output.
For example:
$ perl -le 'print `thiscommanddoesnotexist`';
$ perl -le 'print `ls emptydirectory`';
$ perl -le 'print `perl -e "die;" 2>/dev/null`'
In the 3rd command, if I didn't redirect stderr to /dev/null, you would see an
error message at the console, but perl itself wouldn't see it -- I just
redirected it to avoid confusion. Many people redirect stderr to /dev/null as
a matter of course, to avoid cluttering the output, and this is what results.
It's always a good idea to check the value of $?.
For more control over a running subprocess, you can open a pipe from it:
my $java_program;
open($java_program, "java -jar /your/jar/here.jar |")
or die("Couldn't run java: $!");
Check 'man perlipc' for all the gritty details!
--
Mike Gillis
Languages Development [EMAIL PROTECTED]
ActiveState Software http://www.activestate.com/languages
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs