Tuesday, July 15, 2008

CMD: redirect error output

I write quite a few batch-files these days and want the error messages to be supressed. I had a vague recollection telling me that this was possible, and found it googling, so here it is:


In a sample:

Del *.log /f /q 1>nul 2>nul

Deletes all log-files, hiding output (1>nul) and error output (2>nul). If I remember correctly (3>nul) was hiding printer output. In the old days. You can, of course redirect to files as well:

Del *.txt /f /q 1>out.txt 2>err.txt

Del *.log /f /q 1>>out.txt 2>>err.txt

This sample is supposed to put all the output in out.txt and all the errors in err.txt.


No comments:

Post a Comment