Redirect Output from the Windows Command Line to a Text File

When you type a command on the Windows command line, the output from the command is displayed in the command prompt window. For some commands, the output can be several rows long and sometimes longer than the height of the command window, causing you to scroll to view all of the output.

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.

01_keyboard_greater_than_symbol

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

More posts from the How-To Category

chrome settings.png

Use Multiple Google Accounts in Chrome Web Browser

01Firefox_Without_Tab_Bar.jpg

Configure The Thunderbird Email Client To Autohide Tab Bar

Private Browsing folder at same level as Firefox Portable folder

Enhance Private Browsing in Firefox Portable

Use Microsoft OneNote with Windows Live SkyDrive

Popular Posts This Month

event id

Fix Windows 8 App Opens Then Closes

runas command

5 Windows Alternatives to the Linux sudo Command

5 Utilities for Changing DNS Servers in Windows Reviewed

windows defender

Windows Defender vs. Security Essentials vs Safety Scanner

Comments [1]

  1. oneshot719 says:

    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