Copy CMD Output Directly To The Clipboard
![windows clipboard output](https://www.ghacks.net/wp-content/uploads/2011/10/windows-clipboard-output.jpg)
The Windows command line prompt can be handy at times, and sometimes even the only option to execute a specific command on the operating system. You sometimes may need to copy the output of a command to the Windows Clipboard, for instance to use the output in another application.
Most users that I know handle this either by sending the output to a file with the > filename.ext command or by frantically trying to figure out a way to select and copy the output content in the command prompt window directly. Side note: The latter option got a lot better with the release of Windows 10.
Both methods are not really straightforward and need more time than the process should take in first place. Thankfully though there is a way to copy command prompt outputs directly to the Windows Clipboard, it is only lesser known.
Open the command prompt as usual. You can open it with standard rights or elevated rights by right-clicking on the icon in the start menu and selecting to run it as an administrator. Another option for that is to hold down the Shift-key and the Ctrl-key before selecting the Command Prompt link in the start menu.
Copy CMD Output Directly To The Clipboard
Once there you can copy any output to the clipboard by appending | clip at the end of the command. A basic example is the dir command which outputs all folders and files of the current directory level directly in the command prompt. Please note that you won't see the output anymore on the screen as it is redirected to the clipboard when you use the | clip command.
- dir -- output in the command prompt
- dir > test.txt -- output copied to the file test.txt in the same directory.
- dir | clip -- output copied to the clipboard
The directory command is only a basic example to demonstrate the effect of the | clip command. You can obviously use it for complex commands and outputs as well. Whenever you use the clip command everything that is part of the output is copied to the Windows clipboard.
Did you know about the clip output command? If not, how did you copy the command prompt output until now?
![Copy CMD Output Directly To The Clipboard](https://www.ghacks.net/wp-content/uploads/2011/10/windows-clipboard-output.jpg)
![Ghacks Technology News](https://www.ghacks.net/wp-content/uploads/2005/10/ghacks-technology-news.jpg)
Thank you, Martin! Getting output directly into clip saves a lot of time and effort.
With other tools like AutoHotKey etc, we can further simplify our effort!
Am I the only one who used screenshots to capture output? Very embarrassing, but true.
It’s neat that clip.exe will accept stdin (piped or redirected from a file). I didn’t know about it, and now that I do I can think of many uses.
But why on earth didn’t they make it completely useful by having clip.exe also copy the clipboard contents to stdout?
Cygwin’s /dev/clipboard can be used in both directions, but of course it requires the cygwin emulation layer. That’s a price I’m prepared to pay on my local machine but not on the servers I manage.
Nice tip, Martin!
I use right click, choose MARK, then select whatever I want with the mouse (while left clicking) then right click again, and voilá, my selection gets copied to the clipboard.
This method gives you more control over what you need to copy.
I’m not sure how legal it is to copy the clip.exe from a Windows Server install to a Windows XP machine, so here’s an alternative:
http://unxutils.sourceforge.net/
Here are some ports of common GNU utilities to native Win32. In this context, native means the executables do only depend on the Microsoft C-runtime (msvcrt.dll) and not an emulation layer like that provided by Cygwin tools.
It has the tools pclip and gclip as well as many other useful utilities, fully legal, fully free, and with source code.
The download link on their site doesn’t work however, so use the sourceforge download:
http://sourceforge.net/projects/unxutils/files/unxutils/current/
Great, thanks for the alternative.
perfecto pero en un OS Win 7 en español seria? Inside Win7 Spanish where scribe? “clip=?” thanks
I once knew every command and switch in DOS prior to the Windows advent. Things changed but I still drop back to DOS for a lot of things I do; this is a very welcome addition and thanks a million for it. It will be used frequently, I guarantee it.
Impressive piece of information Martin, and tips like this will elicit a lot of reader responses :-).
Thanks…
Good find or a useful tip. Thanks for sharing it.
Didn’t know this. Thanks, and more thanks for the tip on XP!
I had no idea about this, this is really cool, thanks
Wow, it’s really cool! I’m from MS DOS era, but I didn’t know.
Great tip. I too was unaware of this.
I have been using the edit menu.
Nice readable – and ferry useful article. perhaps its an idea to rehash/refresh us with all possible dos commands and (and this would be an extensive task) (perhaps series of ) what you can do with the dos commands article(s)
Just to echo Paul(US); I’ve been messing about in the DOS shell and realised just how much I’ve forgotten – Windows has made me lazy.
Had to Google the DOS version of pwd – just a simple CD… makes me feel a little embarrassed at how much I’ve forgotten!
wow, man you’re awesome. i’ve always wanted to do it but never really knew it’s possible. Thanks alot man
The app menu for the console window (upper left of window) allows you to copy and paste by ‘marking’ text to copy to the clipboard, or paste. It is not as convenient as piping it to ‘clip’, which I admit I was unaware of.
Specifically within the ‘edit’ submenu
is this a Vista/7 only command, or does this work with earlier version of windows?
According to this article from 2006 (http://pericson.com/2006/03/clip-command-line-utility/) it does not ship with XP but can be used under XP. The blog post links to a download on a respected site. It is probably best to place it in system32 or another path variable folder.
That is cool – I’ve always prefered to work in DOS but sometimes you’re forced into Windows.
I had no idea about using the pipe to send to clipboard (Always assumed pipe was a Unix thing).
I ended up using an ahk script to paste into the command line – this just tops it all off.
Cheers!
It is pretty handy considering that it is a built-in feature.