How to Copy the Command Output to Windows Clipboard
Like it or not, the command prompt is still an indispensable part of your Windows computer because there are still a bunch of things that can only be done by writing commands.
For instance, if the computer isn’t connecting to the Internet, you will probably be interested in the output of the “ping” or the “tracert” command. If you need to print the contents of a directory in Windows, the command “dir” will come to your rescue.
Copy command line output to Windows Clipboard
Now here’s a little trick. If you add the pipe* operator (|) to your command followed by the “clip” command, the output of your original command will get saved to the Windows clipboard and won’t print inside the Command Prompt window.
Here are some examples:
- dir | clip Copy the content of a folder to the clipboard.
- tree | clip Display the recursive directory structure and save it to the clipboard.
- type error.log | clip Place the content of the file error.log to the clipboard.
- sort file.txt | clip Sort the file and save the sorted output to the clipbord.
- ipconfig /all | clip Get details of your network connection for sending to tech support.
The “clip” command may not be available on Windows XP but in that case, you can use the redirect operators, like > and >>, for saving the command output to a text file.
Alternatively, right-click anywhere inside the command window, select Mark from the contextual menu, use the mouse to highlight a block text and then press Enter to save it to the clipboard.
[*] The pipe operator (|) takes the output of one command and directs it into the input of another command which in our case is clip.
Google Developer Expert, Google Cloud Champion
Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India.
Amit has developed several popular Google add-ons including Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory