Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 985
mik Avatar asked Jan 27 '09 08:01

mik


People also ask

Does Windows have stdout and stderr?

The regular output is sent to Standard Out (STDOUT) and the error messages are sent to Standard Error (STDERR). When you redirect console output using the > symbol, you are only redirecting STDOUT. In order to redirect STDERR, you have to specify 2> for the redirection symbol.

How do I redirect a log file in Windows?

To redirect the output of a command to a file, type the command, specify the > or the >> operator, and then provide the path to a file you want to the output redirected to. For example, the ls command lists the files and folders in the current directory.

How do you calculate stderr?

The standard error is calculated by dividing the standard deviation by the sample size's square root. It gives the precision of a sample mean by including the sample-to-sample variability of the sample means.


2 Answers

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.

like image 27
unwind Avatar answered Sep 25 '22 04:09

unwind


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.

like image 200
aphoria Avatar answered Sep 26 '22 04:09

aphoria