Search code examples
pipedosstdoutcommand-promptstderr

DOS stdout stderror pipes syntax


I'm using the following command to pipe the DOS stdout and stderr to my logfile:

run.exe  1> mylog.log 2>&1

My colleague insists on using:

run.exe  > mylog.log 2>1

Which is correct?


This is on Windows 7.


Solution

  • Yours is correct and your colleague's is partially correct.

    The Windows shell redirection operators are essentially the same as those for the Unix shell. The default file handle for the > (redirect output) operator is 1, stdout, so there's no need to specify it as in your example, though it doesn't hurt. If you want to tell the shell to attach the output of one file handle to another (e.g., wire stderr to the same handle as stdout), you need to use >&.

    Your colleague's example here will correctly redirect stdout to mylog.log, but stderr will go into a file named 1.