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:

  1. Run an external command.
  2. Get its output.
  3. Find out if it died (gave an abnormal exit status).
  4. 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.


In reply to Re: trap warnings in $@ by kyle
in thread trap warnings in $@ by mcrswan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.