Just to let you know, we’re an affiliate for Amazon, Bluehost, CJ and Rakuten Marketing and some of the links below are affiliate links, meaning that, at no additional cost to you, I may earn a commission if you click through and make a purchase. Thank you if you use our links, we really appreciate it!
When you type something into the Windows command prompt, the output stays in the Windows command prompt.
This is fine, but what if the command you executed spits out hundreds of lines?
And sometimes, there can be so much output that you have to scroll through it all to view it. Sometimes however, the buffer may get full and you loose some of the output.
So what can you do? Well you could mark the text and copy it to the clipboard, but there's an easier way than that.
This trick that I'm going to show you will enable you to save the entire output to a file.
You basically use the redirection command.
Let me show you what I mean.
The redirection command involves the use of the greater than ">" symbol to direct the output of your command to a file with a name of your choosing.
So for example, say you want to save the output of the net start command to a file called "output.txt", then all you have to do is the following:
First, we need to open a command prompt window.
What I tend to do is first open Windows explorer and navigate to a folder where I'd like to save the text file and open then the command prompt from there. I do this by holding down SHIFT + right mouse button and clicking "Open command window here" as you can see in the picture below:
Then in the command prompt window, type the following command:
net start > output.txt
When the above command is executed, the output will be saved to "output.txt" in the "logs" directory in my documents folder (because that was where I opened the command window from).
Another way to achieve this, is rather than opening the command window from the directory you're saving the text file to, you can just specify the entire path.
So for example, executing the following command will send the console output to the text file in the directory specified, in my case the directory is "C:UsersBarryDocumentslogs".
net start > C:UsersBarryDocumentslogsoutput.txt
Now it's important to note that if the file does not exist, the system will create it for you.
However if the file DOES exist, then the file will be OVERWRITTEN, so just be aware of that before you execute the command.
Now there's another trick you can do which allows to append content to a file that already exists. But instead of using just one chevron, you use two like this: >>.
net start >> C:UsersBarryDocumentslogsoutput.txt
The double redirection operator functions in the same way as the single redirection operator, but instead of actually overwriting the output file that already exists, it will append the console output to the end of the file.
A good use for this might be if you have for example two computers, let's say Computer A and Computer B, and you wanted to obtain similar information from both computers but store it in one file.
You could run the command below on Computer A which would be written to the log file.
net start >> C:UsersBarryDocumentslogsrunning_windows_services.log
You could then run the same command on Computer B and a list of Windows services running on Computer B would be appended to the file rather than overwriting it.
How to Copy the Command Output to Windows Clipboard
If you don't want the output of a file being written to a file, then there is a neat way of copying the output to the Windows clipboard instead.
Basically, all you have to do is add the pipe (|) operator after your command followed by the "clip" command. This will send the output to the Windows clipboard and won't be shown inside the Command Prompt window.
So for example, you could copy the contents of a folder to the clipboard with the following command:
dir | clip
Or you could copy the details of your network connections to the clipboard:
ipconfig /all | clip
You can use any command you wish here. The pipe operator (|) basically takes the output of one command and feeds it into the input of another command ("clip" in our case) and so the output ends up on the Windows clipboard, which I think can be really handy.
Alternatively, to copy the output of the console to the clipboard, you can select Mark from the context menu and then use the mouse to highlight text within the console and then press Enter to save to the clipboard:
However, I think you'll agree that either of the above methods are a lot more convenient and less cumbersome than manually highlighting text to copy to the clipboard.
What do you guys use to save the output of the command prompt in a text file? Let me know in the comments if you have any other methods.