Copy CMD Output Directly To The Clipboard - gHacks Tech 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 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

windows clipboard output

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?

Summary
Copy CMD Output Directly To The Clipboard
Article Name
Copy CMD Output Directly To The Clipboard
Description
The guide explains how you can send any command prompt output to the Windows Clipboard right away using the | clip parameter at the end of commands.
Author
Publisher
Ghacks Technology News
Logo




  • We need your help

    Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.

    We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats (video ads) or subscription fees.

    If you like our content, and would like to help, please consider making a contribution:

    Comments

    1. Dean said on October 20, 2011 at 7:10 pm
      Reply

      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!

      1. Martin Brinkmann said on October 20, 2011 at 7:24 pm
        Reply

        It is pretty handy considering that it is a built-in feature.

    2. The_Flames said on October 20, 2011 at 7:28 pm
      Reply

      is this a Vista/7 only command, or does this work with earlier version of windows?

      1. Martin Brinkmann said on October 20, 2011 at 7:32 pm
        Reply

        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 said on October 20, 2011 at 7:29 pm
      Reply

      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.

      1. bitsum said on October 20, 2011 at 7:31 pm
        Reply

        Specifically within the ‘edit’ submenu

    4. Meena Bassem said on October 20, 2011 at 8:06 pm
      Reply

      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) said on October 20, 2011 at 8:40 pm
      Reply

      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)

      1. Dean said on October 21, 2011 at 11:59 pm
        Reply

        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 said on October 20, 2011 at 9:32 pm
      Reply

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

    7. Visitor said on October 20, 2011 at 10:12 pm
      Reply

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

    8. Steve said on October 20, 2011 at 11:02 pm
      Reply

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

    9. Roman ShaRP said on October 21, 2011 at 10:57 am
      Reply

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

    10. Wombat1369 said on October 21, 2011 at 3:31 pm
      Reply

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

    11. Masoud Sh. said on October 21, 2011 at 4:40 pm
      Reply

      Thanks…

    12. TechBuzzard said on October 21, 2011 at 6:31 pm
      Reply

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

    13. Gemmo said on October 21, 2011 at 11:47 pm
      Reply

      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 said on October 22, 2011 at 12:51 pm
      Reply

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

    15. whino said on October 22, 2011 at 7:57 pm
      Reply

      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/

      1. Martin Brinkmann said on October 22, 2011 at 9:18 pm
        Reply

        Great, thanks for the alternative.

    16. ECLiPSE said on October 23, 2011 at 5:11 am
      Reply

      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 said on October 25, 2011 at 6:48 am
      Reply

      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.

    18. MAW74656 said on August 14, 2012 at 12:00 am
      Reply

      Am I the only one who used screenshots to capture output? Very embarrassing, but true.

    19. Harsha said on October 22, 2012 at 10:06 am
      Reply

      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!

    Leave a Reply