Select the product you need help with
- Internet Explorer
- Windows Phone
- More products
Redirecting Error Messages from Command Prompt: STDERR/STDOUT
Article ID: 110930 - View products that this article applies to.
This article was previously published under Q110930
When redirecting output from an application using the ">" symbol, error messages still print to the screen. This is because error messages are often sent to the Standard Error stream instead of the Standard Out stream.
Output from a console (Command Prompt) application or command is often sent to two separate streams. 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. This selects the second output stream which is STDERR.
EXAMPLEThe command "dir file.xxx" (where file.xxx does not exist) will display the following output:
If you redirect the output to the NUL device using "dir file.xxx > nul", you will still see the error message:
Volume in drive F is Candy Cane Volume Serial Number is 34EC-0876
File Not Found
To redirect the error message to NUL, use the following command:
File Not Found
Or, you can redirect the output to one place, and the errors to another.
You can print the errors and standard output to a single file by using the "&1" command to redirect the output for STDERR to STDOUT and then sending the output from STDOUT to a file:
Article ID: 110930 - Last Review: February 20, 2007 - Revision: 3.3