Search code examples
windowsscriptingbatch-filecmdstderr

How to capture stderr on Windows/DOS?


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> errorfile.log

How do I do it in a CMD script under Windows?


Solution

  • 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.