Please check if $output is really empty or undef (i.e. use defined). If it's really empty then you program really doesn't print anything.

Otherwise: The back ticks return undef in scalar context when the called program fails, i.e. returns a non-null value. This is normally the case when wrong arguments are provided to the program. So your program probably prints the warning but it is not returned by the back ticks because the program call failed.

You could try to use open in order to read the output:

open (my $call, '-|', "$command 2>&1"); $output = join //, <$call>; # or use { local $/; $output = <$call>; } close ($call);
Please see the perldoc -f open for the exact behavior of open in the case of failure.

Update: It looks like the the back ticks return only undef when the given program couldn't be started, i.e. wrong name or permissions, but not when it fails. But checking if the output is really defined is still a good idea. Are you running the perl program under an other user, e.g. over CGI?


In reply to Re: How to trick this program (weird catch-the-output problem)? by mscharrer
in thread How to trick this program (weird catch-the-output problem)? by rovf

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.