Redirecting Stream Handles in Pure Batch
As you know there are these redirection operators:
- > Writes the command output to a file or a device, such as a printer, instead of the Command Prompt window.
- < Reads the command input from a file, instead of reading input from the keyboard.
- >> Appends the command output to the end of a file without deleting the information that is already in the file.
- | Reads the output from one command and writes it to the input of another command. Also known as a pipe.
But there are also these operators:
- >& Writes the output from one handle to the input of another handle.
- <& Reads the input from one handle and writes it to the output of another handle.
By default, you send the command input (that is, the STDIN handle) from your keyboard to Cmd.exe, and then Cmd.exe sends the command output (that is, the STDOUT handle) to the Command Prompt window. But why follow the rules?
Take a look at the numeric values for the handles in cmd:
Description: Keyboard Input
Description: Console Output
Description: Console Error Output
And the rest are handles 3-9 that are empty and/or
defined by individually by other applications.
Now to mess with the handles, you want to specify the handle
numbers with the handle redirection operators on the same line
as your command followed by a space after your command.
This command will redirect the command output and including STDERR to STDOUT, then STDOUT is redirected to output.log