You are confusing two different mechanisms here.

2>&1 is a shell directive, it is nothing to do with Perl. It means: "redirect file descriptor 2 to file descriptor 1". The & indicates a file descriptor rather than a file called "1". File descriptors are indexes to a process's open files and point to kernel's internal tables. 0 (zero) is STDIN, 1 is STDOUT and 2 is STDERR. This is the case on UNIX/Linux systems and on Windows console programs. Shells like the Korn shell (ksh), Bash, and Bourne shell (sh) support this notation, and even cmd.exe and Powershell on Windows. C shell (csh or tcsh) does not, it requires a different syntax.

As others have said, `backticks` or qx capture STDOUT, which is this case includes STDERR output, however you are not capturing it. Usually you would do something like this:
use strict; use warnings; my $capture = `ifconfig 2>&1`;
This enables us to inspect the output (in $capture in this case. If you want the output displayed on the screen then use system instead. If you want both then just print $capture

In reply to Re: how does '2>&1' work ? by cdarke
in thread how does '2>&1' work ? by wildnature

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.