If you look at the documentation in perlop for backticks it provides several strategies; shell redirection of STDERR to STDOUT, swapping STDERR and STDOUT, and even just writing STDERR to a file that you can look at later. It's entirely possible none of these are convenient for your use case. I'd recommend instead going to a module like Capture::Tiny where your code would look something like this:

use Capture::Tiny qw(capture); my ($stdout, $stderr, $exit_code) = capture { system('htmldate', '-u', $url) };

I used the list form of system as well, to avoid exposing $url to the shell; this is a bit of a safety best practice.

You can see here that using the capture function you can run your external call as a system call, and then capture STDOUT, STDERR, and the exit code into distinct variables that you can then inspect after the call.

The Capture::Tiny module consists of less than 430 lines of well-tested code, and has no non-core Perl dependencies, so it should be quite easy to install.


Dave


In reply to Re: Capturing errors from backtick by davido
in thread Capturing errors from backtick by cormanaz

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.