Save or Print Output from Windows Command Prompt to a Text File

Print Page

If you are working with windows command prompt you can directly view the output directly in the command promt window itself. Now suppose you want to save the output/command result to a text file or print it to a hard copy.

For example if you want to save your system information, one thing that you can do is copy from the command prompt window and paste it in a text file and then if you want you can print it.

Instead, there is a better way to easily save the output directly from the command prompt window to a file by using the redirection command.

To use the redirect command, just use the symbol “>” and the file name at the end of the command you want to execute.

For example to redirect output of the systeminfo command to the file systeminfo.txt, enter the following command at the prompt: systeminfo > systeminfo.txt

This will create the file called systeminfo.txt in the current directory you are at, with the output results of systeminfo command.

Now if you want the file to be created at another location on your hard drive, enter the full path to that location: systeminfo >c:\systeminfo.txt

When using a single redirect command, it will always over-write the contents of the file before writing any new data. That is if you have the same file name. So if you want to append data to an existing file, use two redirection symbols as shown in the following example: dir c:\files >> c:\systeminfo.txt

This example adds the output of the dir (directory) command to the end of the file – systeminfo.txt.

If you want to directly redirect the output to devices such as a printer then you can follow the following example:

Say you have a printer connected to LPT1. You would use the following command:
dir c:\files >LPT1

This will print the output for you. You can also use PRN or CON to output data results.