0

I am unable to understand a part of Perl script which is executing an exe.

open(SYSTEM, "$appl 2>&1 |") || die "$!: $appl";

According to this I can understand that it is executing an exe (the variable $appl stores the path of exe along with its args), but I do not understand the part 2>&1. AFAIK it is not arg required by our exe, so it must be some standard convention. Any idea what that does?

PS: Our Perl is a bit old, hence the older syntax for open().

Cool_Coder
  • 4,888
  • 16
  • 57
  • 99

2 Answers2

3

You can see a brief explanation of what 2>&1 is here: In the shell, what does " 2>&1 " mean?

Basically it is telling the command line to redirect any error messages the EXE raises to the standard output where the perl script can pick up the output.

Without this, or when running the EXE from the command line, it may normally direct errors to a separate output (STDERR) to that where information messages appear (STDOUT).

Community
  • 1
  • 1
Jim
  • 128
  • 1
  • 7
2

It is redirecting STDERR to STDOUT.

On program startup, the integer file descriptors associated with the streams stdin, stdout, and stderr are 0, 1, and 2

Unix File Descriptors

arunxls
  • 124
  • 1
  • 9