Redirect Windows cmd stdout and stderr to a single file

前端 未结 7 1773
醉梦人生
醉梦人生 2020-11-22 10:11

I\'m trying to redirect all output (stdout + stderr) of a DOS command to a single file:

C:\\>dir 1> a.txt 2> a.txt
The process cannot access the fil         


        
7条回答
  •  无人及你
    2020-11-22 10:53

    Anders Lindahl's answer is correct, but it should be noted that if you are redirecting stdout to a file and want to redirect stderr as well then you MUST ensure that 2>&1 is specified AFTER the 1> redirect, otherwise it will not work.

    REM *** WARNING: THIS WILL NOT REDIRECT STDERR TO STDOUT ****
    dir 2>&1 > a.txt
    

提交回复
热议问题