A string which is (possibly) interpolated and then executed as a system command with /bin/sh or its equivalent. Shell wildcards, pipes, and redirections will be honored. The collected standard output of the command is returned; standard error is unaffected.

Given the bold statement, I call "bad design" on the last phrase. This has been very frustrating. Perl's philosophy of sometimes guessing what I mean rather than taking what I say at face value has now officially really ticked me off. At the very least, this construct should produce a warning message!

The documentation is correct. The backticks execute /bin/sh and capture the STDOUT of /bin/sh. the string you specify, including the redirection, is processed by /bin/sh -- perl (and hte backticks) don't know or care that you have asked /bin/sh to execut "cmd" and redirect cmd's STDERR to cmd's STDOUT (which then becomes the STDOUT of /bin/sh). All perl does is is take /bin/sh's STDOUT and give that to you.

See the previous comments explaining why it doesn't seem like it's working because of your flawed test case

The example you said does work would also appear to fail, if you had written it to work the same way (ie: print in single scalar variable in which you have slurped all of the data from F)


In reply to Re: backticks fail to capture stderr even with explicit redirection by hossman
in thread backticks fail to capture stderr even with explicit redirection by keithhanlan

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.