I think eval might not be the right tool to use here. In Perl, eval takes a string (or block) of Perl code and executes it. If you put a backtick expression where it's looking for a string, it's going to take the output of the shell command in the backticks and then try to execute it as Perl. Here's a demonstration:
sub whoops {
print "whoops() called\n";
}
eval `echo whoops`;
print $@ ? "EVAL ERROR: $@\n" : "no error!\n";
eval `echo no_such_sub`;
print $@ ? "EVAL ERROR: $@\n" : "no error!\n";
__END__
whoops() called
no error!
EVAL ERROR: Bareword "no_such_sub" not allowed while "strict subs" in
+use at (eval 2) line 1.
I'm guessing that what you want to do is:
- Run an external command.
- Get its output.
- Find out if it died (gave an abnormal exit status).
- Find out also if it spit out a warning (output anything on STDERR).
I think the responses in Parsing STDERR and STDOUT at the same time might help here. I think that IPC::Run can do all of this, but I haven't used it myself. |