Little-known command line utility: clip


Windows Vista includes a tiny command line utility called clip. All it does is paste its stdin onto the clipboard.

dir | clip
echo hey | clip

For the opposite direction, I use a little perl script:

use Win32::Clipboard;
print Win32::Clipboard::GetText();
Comments (55)
  1. Anonymous says:

    This program is solid gold!

    (Now what’s the equivalent PowerShell cmdlet …)

  2. Anonymous says:

    Seems to work on XP64 also

  3. Anonymous says:

    But… if you need to install perl, you already lost! Right? :)

  4. Anonymous says:

    I made my own version of clip.exe, when run with empty std in, it displays the current clipboard, run on every version of windows since nt4/9x and it is still smaller than the MS version

  5. Anonymous says:

    Interesting; I have a short little C program I wrote that does the same thing.  Cygwin also comes with the /dev/clipboard pseudofile which does the same thing, see http://williammitchell.blogspot.com/2008/03/fun-with-cygwins-devclipboard.html , although it doesn’t show up by default under a directory listing of /dev.  Use http://cygwin.com/ml/cygwin/2004-03/txt00028.txt to fix that.

    For the Mac OS X users out there, there are the command line utilities pbcopy and pbpaste for copying to and pasting from the pasteboard.

  6. Anonymous says:

    ipconfig /all | clip && notepad then ctrl-v

  7. Mike Dunn says:

    The most excellent 4NT uses the pseudo-file clip: for the same thing, and it works for both input and output:

    dir /s > clip:

    type clip:

  8. Anonymous says:

    4NT, JPsoft’s cmd.exe replacement, extends the command prompt elegantly with the CLIP: pseudo-device. Thus:

    echo hello > clip:

    echo there >> clip:

    type clip:

    and so on.

  9. Anonymous says:

    Nifty. xclip is the X11 equivalent, by the way.

  10. Anonymous says:

    for those on cygwin

    $ putclip –help

    putclip version 0.2.0

     Copy stdin to the Windows Clipboard

    Usage: putclip [OPTION…]

    General options

     -d, –dos         Clipboard text will have DOS line endings.

     -u, –unix        Clipboard text will have UNIX line endings.

     -n, –no-conv     Do not translate line endings.

    Help options

     -?, –help        Show this help message

     –usage           Display brief usage message

     –version         Display version information

     –license         Display licensing information

    NOTE: by default, no line ending conversion is performed.

    $ getclip –help

    getclip version 0.2.0

     Copy the Windows Clipboard to stdout

    Usage: getclip [OPTION…]

    General options

     -d, –dos         Output text will have DOS line endings.

     -u, –unix        Output text will have UNIX line endings.

     -n, –no-conv     Do not translate line endings.

    Help options

     -?, –help        Show this help message

     –usage           Display brief usage message

     –version         Display version information

     –license         Display licensing information

    NOTE: by default, no line ending conversion is performed.

    winclip

    http://dmst.aueb.gr/dds/sw/outwit/winclip.html

    is a nifty windows executable that does both

  11. Anonymous says:

    > For the opposite direction, I use a little perl script

    Now you have two problems.

    [I would if I were recommending this to other people. But I’m not. I’m just mentioning what I use. Next time I won’t bother. -Raymond]
  12. Anonymous says:

    I found this worked just find in PowerShell on Windows 7

    PS C:> ps | clip.exe

  13. Anonymous says:

    @Mark

    > For the opposite direction, I use a little perl script

    Now you have two problems.

    perl is a problem? what’s the problem with perl?

    In unix environments perl is almost a part of the system… Doesn’t seem to bother them…

    I wouldn’t say that it hurts to have it around in Windows either… more if you’re a developer.

    Bounus: try out App::Ack. It’s like grep on steroids for developers. Think it works on Windows too :)

  14. Anonymous says:

    Wow. What’s with people suddenly not realising that "now you have two problems" is a joke? Collective SOHF much?

  15. DWalker59 says:

    @pplu:  Mark’s comment was an echo of Raymond’s old post that said something like "When faced with a problem, some people say "I know!  I’ll use regular expressions".  Now you have two problems."  [The second problem is installing some software that can do regular expressions.]

    I think Raymond reacted a little harshly to Mark’s comment; after all, Mark may have said it half in jest.  :-)

  16. Anonymous says:

    It was indeed in jest, although I was a little concerned Raymond’s heard that one before.  But seriously, how would you do the same without Perl?  In a bind, I’d probably use ntsd.

    Anyway, since it’s clearly smiley time, pplu: that’s like saying "it’s easy with Powershell" to a Unix admin ;-)

  17. Anonymous says:

    clip.exe is The Best Program Ever.  Well, second best, because I wrote my own basically as soon as I could code on Windows.  Essential for command prompt people everywhere.

  18. Anonymous says:

    Wow. What’s with people suddenly not realising that

    "now you have two problems" is a joke?

    A joke used by people as big of dicks as jwz.

  19. Anonymous says:

    I have been using gclip and pclip from UnxUtils (http://unxutils.sourceforge.net/) for years

  20. Anonymous says:

    woa woa woa!… I’ve seen people come up with powershell scripts for this purpose

    Is there any central resource to find this and other built in command line tools? (did a few searches, got nothing useful back)

  21. Anonymous says:

    I basically wrote my own version in C#, which supports reading and writing to the clipboard, as well as writing a string from the command-line.

  22. Anonymous says:

    @Someone else – right with you. i jumped on Google to search for the powershell equiv before I even finished the article. All I could find is this community extension (PSCX):

    http://keithhill.spaces.live.com/Blog/cns!5A8D2641E0963A97!680.entry

    @Raymond – come on… you had to know what the response would be as soon as you typed "Perl". Don’t take it personally ;-)

  23. Anonymous says:

    "I think Raymond reacted a little harshly to Mark’s comment; after all, Mark may have said it half in jest.  :-)"

    People come here knowing that Raymond has "the social skills of a thermonuclear device"!

  24. Anonymous says:

    Thanks for the post.  You’ve saved me hundreds of minutes.

  25. Anonymous says:

    For mac users in this thread, you have the same magic with ‘pbcopy/pbpaste’.

  26. Anonymous says:

    @pplu Yes, ack works on Windows as well.  It’s a standalone program you can download as a single file.  See http://betterthangrep.com/

    I’ve had to eschew many Unix-specific changes in the name of keeping ack platform-neutral.

  27. Anonymous says:

    In Powershell and if you are running Windows 7 you don’t need to install anything:

    function p {

    add-type -an system.windows.forms

    }

  28. Anonymous says:

    <i>…I use a little perl script:</i>

    When, oh when, will Windows start including useful scripting languages like Python and Perl in the box as a standard install?  Mac & Linux do this and it is so incredibly useful to know you’ve got scripting languages installed when sharing things like this.

  29. Anonymous says:

    Tis sounds like a half-written program (but a very useful one). Would it be so hard to add a command-line option to take the clipboard contents (text only, of course) and pipe it to stdout? Or would there be problems with that?

  30. Anonymous says:

    Ages ago I wrote a similiar program, that depending on its executable name would copy the contents to the clipboard, or paste the contents of the clipboard.  It could also copy stdin to a new notepad session bypassing the clipboard.

    Maybe one day I’ll release it, though I’ve always assumed something like this is one of the first things a dev writes for themselves.

  31. Anonymous says:

    J Peterson: Out of curiosity, what makes you think it doesn’t?

    Even if you don’t count Batch as a scripting language (and I wouldn’t blame you), there’s VBScript and JScript. JScript isn’t very popular, but VBScript is used all over. And of any current Windows version will have PowerShell as well.

    And it’s not like VBScript is new– I remember fiddling around with it in Windows 98.

    Of course, you’re probably going to use the common "out" of saying "I said USEFUL scripting languages!" implying that VBScript, which thousands of people use daily, isn’t "useful" in some way.

  32. Anonymous says:

    alt+space e p puts the clipboard on the command line, no?

  33. Anonymous says:

    Console paste works well when you’re using it with something that won’t bail out halfway through your paste (which in my case is usually vim in paste mode).

  34. Anonymous says:

    @WndSks

    It also probably crashes on some large percentage of configurations.

    A fair amount of Raymond’s posts do explain the great lengths that MS has gone to ensure minimal compatibility issues.

    … "Oh you need to uninstall <insert-essential program-name-here> and it will stop crashing"

  35. Anonymous says:

    > Would it be so hard to add a command-line option to take the clipboard contents (text only, of course) and pipe it to stdout?

    Do one thing and do it well…

    clip.exe to read to the clipboard

    clop.exe to write clipboard to stdout

  36. Anonymous says:

    I wrote utilities that did this many years ago, I called my ccopy and ppaste. They also handled files names as well as text. You could ccopy *.* and the paste the files into explorer. Or you could paste the files names into notepad.

    Unfortunately they are lost in the sands of time.

  37. Anonymous says:

    Please continue, these tips are really helpful and interesting

  38. Yuhong Bao says:

    Windows 3.x and 9x had a DOS interface for accessing the clipboard. It was INT 2F 17xx. Read about it in Ralf Brown’s Interrupt List.

  39. Anonymous says:

    It’s in Server 2003.  A version is also in one of the resource kits (2000?  98? Who knows, it goes with me everywhere)

    CLIP v2.2 – Command line Clipboard Utility

    Copyright (c) 1998,99 by Dave Navarro, Jr. (dave@basicguru.com)

    Usage: CLIP [filename] [options]

     filename        Text file to be read and placed into the clipboard.

                     Long filenames are supported.

     /r              Reads any text in the clipboard and writes to the

                     the specified ‘filename’.

    No perl necessary with that version.

  40. anony.muos says:

    And why was the more useful clipboard viewer removed?

  41. Anonymous says:

    Windows *does* include a useful scripting language like Python or Perl. Three, actually: VBScript, JScript and PowerShell.

  42. Anonymous says:

    @someone:

    You might want to install it from your Windows CD as per http://www.computertim.com/howto/article.php?topic=windows&idn=93

  43. Anonymous says:

    @WndSks

    "and it is still smaller than the MS version"

    Yes, I could do that as well, but compatibility, SDL standards, and idiot proofing; would make it a bit larger.

  44. Anonymous says:

    I recommend the really small UnxUtils package at

    http://sourceforge.net/projects/unxutils/

    which is a Win32 port of some Unix commands.  It contains the pclip and gclip commands for working with the clipboard as well.

    For instance,

    pclip | sort | gclip

    would sort the text on the clipboard.

  45. Anonymous says:

    You can also take the version out of 2003 and copy it to XP and it works fine there.

    Possibly you can do this with the Vista one to XP too, but I haven’t tried (it might be the exact same code).

    More: http://wp.me/p2I5L-y

  46. Anonymous says:

    @echobeach2:

    ipconfig /all >%temp%ipconfig.txt && notepad %temp%ipconfig.txt

    And then you don’t need Ctrl-V, which doesn’t get saved in the command history

  47. Anonymous says:

    Regarding the size of clip.exe: DIR reports that it’s 32,256 bytes on my Windows 7 64-bit installation. Is that considered large? Why this obsession with "smaller"? Correct wins every time.

  48. Anonymous says:

    Conversely (and for completeness, the perl equivalent to put text on the clipboard:

    use Win32::Clipboard;

    local $/=undef;

    Win32::Clipboard::Set(<>);

  49. Anonymous says:

    @Gaspar: It’s not like this is a complex program we are talking about here

    @Dale: What idiot proofing?, it has no options, it only does one of two things depending on whether stdin is empty or not. It is smaller because it is written in VC6 pure win32 with no runtime libs (No about/usage description either, there is still some padding in the file so it could be added and still stay @ 2kb)

  50. Anonymous says:

    > @Dale: What idiot proofing?, it has no options, it only does one of two things depending on whether stdin is empty or not.

    What about the simple idiot case of your batch file calls a program which legitimately outputs zero bytes and instead of the data being piped into the clipboard, (eg clipboard being emptied and a CF_TEXT handle of zero bytes being put into the clipboard), the viewer pops up instead.

  51. Anonymous says:

    @porter: I just checked my source, the actual logic is:

    display current clipboard if: we did not just set it OR stdout is redirected

    meaning: "echo.foo|clip|cat" will both copy foo to the clipboard and print foo, "output0|clip" will not output anything

  52. GregM says:

    "I have been using gclip and pclip from UnxUtils for years"

    How did I not know about those?  I’ve had those on my computer for years and didn’t know it!

  53. Anonymous says:

    > I’ve had those on my computer for years and didn’t know it!

    Whereas I’ve had clipbrd.exe since Windows 1.0 and used it all those years, and now I don’t because MS has taken it away.

  54. Anonymous says:

    @Mark

    Anyway, since it’s clearly smiley time, pplu: that’s like saying "it’s easy with Powershell" to a Unix admin ;-)

    Joke understood. +1 Smiley :D

  55. Anonymous says:

    GregM: I bet you didn’t know about gplay, either

Comments are closed.