Welcome to MSDN Blogs Sign in | Join | Help

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();
Published Tuesday, November 10, 2009 7:00 AM by oldnewthing
Filed under:

Comments

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 7:13 AM by someone else

This program is solid gold!

(Now what's the equivalent PowerShell cmdlet ...)

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 7:13 AM by Rutger

Seems to work on XP64 also

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 7:28 AM by Pierre B.

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

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 7:36 AM by WndSks

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

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 7:44 AM by Adam Rosenfield

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.

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 7:55 AM by echobeach2

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

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 8:03 AM by Mike Dunn v2.0

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:

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 8:03 AM by Tony Lezard

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.

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 8:07 AM by Daniel Colascione

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

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 8:27 AM by ShuggyCoUk

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

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 8:29 AM by Mark

> 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]

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 8:40 AM by Roland Rabien

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.

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 8:49 AM by Jeffery Hicks

I found this worked just find in PowerShell on Windows 7

PS C:\> ps | clip.exe

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 9:16 AM by pplu

@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 :)

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 9:20 AM by Karellen

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

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 9:23 AM by DWalker59

@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.  :-)

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 9:32 AM by Mark

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 ;-)

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 10:02 AM by Granka

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.

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 10:23 AM by me

>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.

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 10:31 AM by KJK::Hyperion

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

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 10:34 AM by Eber Irigoyen

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)

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 10:35 AM by Miff

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.

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 10:57 AM by David J

@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 ;-)

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 10:59 AM by njkayaker

"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"!

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 11:29 AM by Lawrence

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

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 11:43 AM by Joshua Barratt

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

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 11:58 AM by Andy Lester

@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.

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 12:14 PM by Luke

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

function p {

add-type -an system.windows.forms

[System.Windows.Forms.Clipboard]::GetText()

}

# When is Windows going to include Python & Perl?

Tuesday, November 10, 2009 1:14 PM by J. Peterson

<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.

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 1:32 PM by someone else

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

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 2:46 PM by Pax

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?

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 2:52 PM by Scott

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.

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 3:01 PM by James Schend

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.

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 3:03 PM by nickj

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

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 3:35 PM by Neil

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).

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 4:13 PM by Gaspar

@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"

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 4:31 PM by porter

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

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 6:30 PM by hereafter

Please continue, these tips are really helpful and interesting

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 6:58 PM by yuhong2

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.

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 7:52 PM by Bryan Price

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.

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 8:12 PM by someone

And why was the more useful clipboard viewer removed?

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 10:47 PM by Drak

@someone:

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

# re: Little-known command line utility: clip

Tuesday, November 10, 2009 10:56 PM by Dale

@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.

# re: Little-known command line utility: clip

Wednesday, November 11, 2009 12:46 AM by The Mad Doctor

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.

# re: Little-known command line utility: clip

Wednesday, November 11, 2009 1:09 AM by AdamV

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

# re: Little-known command line utility: clip

Wednesday, November 11, 2009 2:04 AM by Jonathan

@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

# re: Little-known command line utility: clip

Wednesday, November 11, 2009 2:40 AM by Paul M. Parks

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.

# re: Little-known command line utility: clip

Wednesday, November 11, 2009 3:55 AM by Chris J

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

use Win32::Clipboard;

local $/=undef;

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

# re: Little-known command line utility: clip

Wednesday, November 11, 2009 5:07 AM by WndSks

@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)

# re: Little-known command line utility: clip

Wednesday, November 11, 2009 6:35 AM by porter

>> @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.

# re: Little-known command line utility: clip

Wednesday, November 11, 2009 8:19 AM by WndSks

@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

# re: Little-known command line utility: clip

Wednesday, November 11, 2009 11:23 AM by GregM

"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!

# re: Little-known command line utility: clip

Wednesday, November 11, 2009 2:41 PM by porter

>> 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.

# re: Little-known command line utility: clip

Thursday, November 12, 2009 1:53 AM by pplu

@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

# re: Little-known command line utility: clip

Monday, November 16, 2009 6:04 AM by KJK::Hyperion

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

New Comments to this post are disabled
 
Page view tracker