Redirection
Redirection characters change where a command gets information from or sends
information to.
Redirecting Command Input and Output
Unless you specify otherwise, Windows NT receives input from your keyboard and
sends output to your screen. Sometimes it is useful to redirect the input or
output to a file or a printer. For example, you might want to redirect a
directory listing from the screen to a file.
To redirect the input or output of a command, you use one of the following
redirection characters:
The greater-than sign (>) sends the output of a command to a file or a device,
such as a printer.
The less-than sign (<) takes the input needed for a command from a file rather
than from the keyboard.
The double greater-than sign (>>) adds output from a command to the end of a
file without deleting the information already in the file.
Redirecting the Output of a Command
Almost all commands send output to your screen. Even commands that send output
to a drive or printer also display messages and prompts on your screen.
To redirect the output from the screen to a file or printer, use the
greater-than sign (>). You can use the greater-than sign with most Windows NT commands.
For example, in the following command, the directory listing produced by the dir command is redirected to the DIRLIST.TXT file:
dir > dirlist.txt
If the DIRLIST.TXT file doesn't exist, Windows NT creates it. If DIRLIST.TXT
exists, Windows NT replaces the information in the file with the output from the dir command.
To add the output from a command to the end of a file without losing any of
the information already in the file, use a double greater-than sign (>>). For
example, in the following command, the directory listing produced by the dir command is appended to the DIRLIST.TXT file:
dir >> dirlist.txt
Note
Some command output, such as error messages, may not be redirected when using
the greater-than sign (>).
Redirecting the Input to a Command
Just as you can send the output of a command to a file or printer rather than
to your screen, you can take the input for a command from a file rather than
from the keyboard. To take input from a file, use the less-than sign (<). For
example, the following command takes the input for the sort command from the LIST.TXT file:
sort < list.txt
Windows NT alphabetizes the lines of the LIST.TXT file and displays the result
on your screen.