How to capture stderr on Windows/DOS?

后端 未结 2 1924
情歌与酒
情歌与酒 2020-12-13 13:23

I want to capture the errors from a script into a file instead of to the screen.

In *nix, this is done with stderr redirection, usually

echo \"Error\         


        
相关标签:
2条回答
  • 2020-12-13 13:48

    That should work in Win32, too.

    If you have already redirected stdout, and want stderr redirected to the same file, you must use the 2>& special form, rather than just specifying the same file twice. Otherwise you'll get a "file busy" error.

    0 讨论(0)
  • 2020-12-13 13:56

    For example:

    PSKILL NOTEPAD >output.txt 2>&1
    

    This will direct stdout and stderr to a file name output.txt.

    See Underused features of Windows batch files for more details.

    0 讨论(0)
提交回复
热议问题