How to Redirect Windows Command Line Output to a Text File



RECOMMENDED: Click here to fix Windows errors and optimize system performance

On Windows 10, the ability to save the output of a PowerShell or Command Prompt to a text file can be useful in many cases. For example, when you are solving a problem, it is a convenient way to export and analyze the results of the command, or you can share the results with someone who can help you. You can print the command output to a text file to save system configurations for documentation purposes, and much more.

Although you can simply select the content, right-click on the selection to copy the content to the clipboard, and then paste it into a text file, this method requires additional steps that you can avoid by using a single command line with the “Redirect Output to File” function.

In this Windows 10 guide, we walk you through the steps for saving the command output to a text file, whether you use the command prompt or PowerShell.

How to Save the Command Prompt Output to a Text File in Windows 10

If the output of an application is redirected with the “>” symbol, error messages are always printed on the display. This is because error messages are often sent to the standard error stream instead of the standard output stream.



January 2021 Update:

We now recommend using this tool for your error. Additionally, this tool fixes common computer errors, protects you against file loss, malware, hardware failures and optimizes your PC for maximum performance. You can fix your PC problems quickly and prevent others from happening with this software:

  • Step 1 : Download PC Repair & Optimizer Tool (Windows 10, 8, 7, XP, Vista – Microsoft Gold Certified).
  • Step 2 : Click “Start Scan” to find Windows registry issues that could be causing PC problems.
  • Step 3 : Click “Repair All” to fix all issues.

download



The output of a console application (command prompt) or a command is often sent to two separate data streams. Regular output is sent to Standard Out (STDOUT) and error messages are sent to Standard Error (STDERR). If you redirect the console output with the “>” symbol, you redirect only STDOUT. To redirect STDERR, you must specify “2>” for the redirection icon. This will select the second output stream, which is STDERR.

To redirect the output of a command to a text file instead of printing it on the screen in the command window, just execute the command and add it with the “>” symbol in square brackets, which is called “redirection” accordingly.

For example, if you want to save the output of the DIR function in a text file instead of scrolling the screen page by page in the command window, you should use the

DIR > some-descriptive-filename.txt
like this, where we ran the DIR command from the C:\ directory and saved the output in the root directory of drive D as “c-drive-directory-output.txt”.

Note that the output is not displayed in the command window above, but when we open the text document, we see the full command output :

Any command having command window output (regardless of its size) can be joined with > filename.txt and the output is saved to the specified text file.

In addition to running the command once, you can also modify it slightly to copy the sequential output to the same text file. For example, suppose you want to send the output of the same command in the same text file before and after making some changes (for example, restarting the router and getting a new IP address). You can start the command first with a single angle bracket “>” and then repeat subsequent instances of the same command with a double angle bracket “>>”.

Conclusion

This allows us to store any number of order outputs in a text file for easy access or to share the information with others as needed.

https://ss64.com/nt/syntax-redirection.html



RECOMMENDED: Click here to troubleshoot Windows errors and optimize system performance