ghacks Technology News

Copy CMD Output Directly To The Clipboard

The Windows command line prompt can be handy at times and sometimes even the only option to execute a specific command in 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 contents in the command prompt window directly.

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.

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.

windows clipboard output

  • 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?

Related Articles:

Copy Command Line Outputs Directly To The Clipboard
Firefox AutoCopy, Copy Text Automatically To The Clipboard
Copy Tables in Firefox to the Clipboard
Enable Quick Edit Mode To Copy Command Prompt Items More Efficiently
Windows Clipboard Software

Enjoyed the article?: Then sign-up for our free newsletter or RSS feed to kick off your day with the latest technology news and tips, or share the article with your friends and contacts on Facebook, Twitter or Google+ using the icons below.



About the Author:Martin Brinkmann is a journalist from Germany who founded Ghacks Technology News Back in 2005. He is passionate about all things tech and knows the Internet and computers like the back of his hand. You can follow Martin on Facebook or Twitter.

Author: , Thursday October 20, 2011 -
Tags:, , ,


Responses so far:

  1. Dean says:

    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!

  2. The_Flames says:

    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.

  3. bitsum says:

    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.

  4. wow, man you’re awesome. i’ve always wanted to do it but never really knew it’s possible. Thanks alot man

  5. Paul(us) says:

    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)

    • Dean says:

      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!

  6. Robert Palmar says:

    Great tip. I too was unaware of this.
    I have been using the edit menu.

  7. Visitor says:

    Wow, it’s really cool! I’m from MS DOS era, but I didn’t know.

  8. Steve says:

    I had no idea about this, this is really cool, thanks

  9. Roman ShaRP says:

    Didn’t know this. Thanks, and more thanks for the tip on XP!

  10. Wombat1369 says:

    Good find or a useful tip. Thanks for sharing it.

  11. Masoud Sh. says:

    Thanks…

  12. TechBuzzard says:

    Impressive piece of information Martin, and tips like this will elicit a lot of reader responses :-).

  13. Gemmo says:

    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.

  14. cyrux says:

    perfecto pero en un OS Win 7 en español seria? Inside Win7 Spanish where scribe? “clip=?” thanks

  15. whino says:

    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/

  16. ECLiPSE says:

    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.

  17. Ross Presser says:

    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.

Leave a Reply   Follow Ghacks   Subscribe To Comment Rss

Subscribe without commenting

© 2005-2012 Ghacks.net. All Rights Reserved. Privacy Policy - About Us