Redirect Output from the Windows Command Line to a Text File


If you want to avoid this, or you want to save a copy of the output generated by a command, you can copy the text from the command window and paste it into a text file. However, there is an easier method of “copying” output to a text file. You use the redirection command.

To use the redirection command, use the “>” symbol and the filename at the end of the command you want to execute.


For example, if you want to save the output from the ipconfig command (displays networking settings), open the command window and type the following command.

ipconfig /all > network_info.txt

NOTE: This creates the file, network_info.txt, in the current directory. In this example, shown in the following image, the file will be saved to the C:\network_info directory. If you want to save the file to a different directory you can specify the full path of the directory in the command as follows:

ipconfig /all > c:\my_directory\network_info.txt

Using the ipconfig command with redirection

Once you enter the command and press Enter, you are returned to the command prompt. The output is sent to the text file, but not to the screen, so you do not see the output.

Returned to command prompt

The network_info.txt file is created in the current directory. To view the output, type the following command to open the text file in Notepad:

notepad.exe network_info.txt

NOTE: If you saved the file to a different directory, be sure to put the full path to the file after “notepad.exe” on the command line as follows:

notepad.exe C:\my_directory\network_info.txt

Text file created

Here is an example of the output if the ipconfig command in a text file.

Output in text file

To close Notepad, select Exit from the File menu.

Exiting Notepad

To close the command window, type exit at the command prompt and press Enter.

Exiting the command window

NOTE: If you use the same filename a second time, that file will be overwritten and any output it previously contained will be lost. To preserve your previous output, use a different filename or you can append the output to the end of an existing file. To append data to an existing file, use two redirection symbols as shown below:

dir c:\my_music >> network_info.txt

NOTE: Redirection is also useful for saving directory listings. The previous command saves a listing of the c:\my_music directory into the end of the network_info.txt file.

by Lori Kaufman

Comments [1]

  1. there are 2 ways to do this.

    echo test message > "test.txt"

    ^that erases what is already on that file and creates a new one

    echo test message >> "test.txt"

    ^that adds a new line with the text to the already existing file.

    that might help someone

Leave a Reply
