Redirecting command output to files
Posted: (EET/GMT+2)
Windows command-line programs normally display their output in the Command Prompt window. Using output redirection, you can instead save the output into a file. This can be very useful.
To save the output to a file, use the greater than character (>). For instance:
dir > files.txt
Instead of displaying the directory listing on the screen, Windows writes it into files.txt. You need to be careful however: if the destination file already exists, > replaces its contents.
To append output to an existing file, use two greater than characters:
dir >> files.txt
Redirection becomes particularly useful with diagnostic commands:
ipconfig /all > network.txt ping server >> network.txt
You can then examine the results with a text editor, archive them, or send them to somebody helping diagnose the problem.
Output can also be passed directly from one command to another using the pipe character (|). For example:
dir | more
This displays a long directory listing one screen at a time. I like to do this when writing batch files or collecting command-line diagnostic information.
Hope this helps!