in reply to how does '2>&1' work ?

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

Replies are listed 'Best First'.
Re^2: how does '2>&1' work ?
by wildnature (Novice) on Feb 23, 2011 at 01:50 UTC

    But I do encounter such a question:

    case 1:

     use strict;  my $cmd = "dumpcap -i eth0 -b duration:10 -w \\media\\Work\\abc.pcap";  `$cmd`

    "dumpcap" itself will print some infomation, if I add 2>&1 behind $cmd, such as `$cmd 2>&1`, no infomation displayed. But if I do not add 2>&1, information do displays

    in another case, If I change $cmd to :

     my $cmd = "ifconfig";

    There is no information displayed in shell no matter If I add 2>&1 or not

    Why is this difference ?

      That means that dumpcap printed some information to STDERR and ifconfig didn't.

        Great! I got it. Thanks a lot :)

      Why is this difference ?

      Why is dumpcap different from ifconfig? Because it wants to be different?