Windows

Copy and paste from Windows XP Pro's command prompt straight to the Clipboard

If you need to copy output from a command and paste it into a Windows program, such as Notepad, while working at the command prompt, chances are you'll try to use the Mark and Copy commands on the command prompt's Edit menu. Greg Shultz shows a better way to get information from a command prompt and onto the Clipboard.

If you need to copy output from a command and paste it into a Windows program, such as Notepad, while working at the command prompt, chances are you'll try to use the Mark and Copy commands on the command prompt's Edit menu. A better way to get information from a command prompt and onto the Clipboard is the Clip.exe command line tool.

Clip.exe comes with Windows Server 2003, but it also works in Windows XP Professional. Simply copy Clip.exe from the Windows\System32 directory on a Windows Server 2003 system, and then paste it into the Windows\System32 directory on a Windows XP system. (If you don't have access to Windows Server 2003, you can download a copy of Clip.exe from Daniel Petri's IT Knowledgebase site.)

Once you have a copy of Clip.exe on your Windows XP system, using it is as easy as appending the pipe and the clip command (| clip) to the end of your command line. For example, you can use this command to copy the directory listing to the clipboard (Dir | clip), or you can use it to collect, copy, and paste the results of the Ipconfig command (Ipconfig /all | clip).

Note: This tip applies only to Windows XP Professional.

Miss a Windows XP tip?

Check out the Windows XP archive, and get more hands-on Windows XP tips.

Stay on top of the latest XP tips and tricks with our free Windows XP newsletter, delivered each Thursday. Automatically sign up today!

About

Greg Shultz is a freelance Technical Writer. Previously, he has worked as Documentation Specialist in the software industry, a Technical Support Specialist in educational industry, and a Technical Journalist in the computer publishing industry.

61 comments
frowzin
frowzin

If you add "nul" to your redirect, the contents of the file open automatically in Notepad. Try ipconfig /all >nul . It works in XP Pro and Vista Business!

naxnxtzoyzjv
naxnxtzoyzjv

Is it really allowed to copy utilities from Windows 2003 to other versions of Windows? Me thinks this breaks the copyright and this tip is illegal.

MWRMWR
MWRMWR

Use clipboard server (clipbrd.exe)... and when that does not appear to work, you'll remember you forgot to start the clip board service (goto Services in manage Computer) and to do that you need to enable and start network dde and network dde DSDM and then enable and start clipboard server. It's almost as if Micro$oft didn't want you to still be using DOS. Why would that be :-} WYGIWYS

yuwadi
yuwadi

With commandxpress, copying is as easy as one or two clicks.

justin.w.walsh
justin.w.walsh

Well I wasn't so luckywith clip.exe. But I already have a great shareware product : FastStone Capture. I had 30 days trial and I discovered I could not do without it so the $19.95 was really worth it. The other reason is: I'm trying to wean myself off Windows altogether. I use another great product called LitePC from LitePC.com and Mozilla Firefox. This ensures that that I have everything I want and nothing I don't.

Mike
Mike

The major use of this idea is to be able to insert text into ANYTHING the clipboard works in, e.g. MS products (of course), but also many other windows programs, google programs, lesser used email progs, etc. All types of programs without going through RE-selecting and pasting the text (with the same clipboard). You can still use the old ways if it suits the purpose or use some arcane method that most people would have to research the command, redirections or such.

bkrateku
bkrateku

You can also do the same thing by highlighting what you want, then just hit Enter and it will copy it. Takes another step or two, but this can be handy when you don't want everything from the output (like router configs, etc.). Alternatively, you can also write directly to a file by using the > and >>. If you want to create a new file, you can use either one, but the > will overwrite an existing file with the same name and >> will append to it. For example... ping mypc > c:\ping.txt - creates a new file or overwrite existing one by the same name. ping mypc >> c:\ping.txt - creates a new file or appends to an existing one with the same name. > is pretty handy, but I use >> more. Below is a good example of pinging a range of PCs and network devices to see what is in use by using the >> to output the results to a text file. for /L %d IN (1,1,50) do ping -a 192.168.1.%d >> c:\ping.txt Use that on a command line to ping the first 50 IPs of the 192.168.1.0 network and write the results to the text file. Cheap network scanner I guess...

BlueKnight
BlueKnight

Great tip and I'll use it at home. Unfortunately clip.exe won't run under Windows 2000 Pro and the command window trick doesn't work on Win2K either, so I'll keep piping to a file. Anybody know if there's a Win2K version?

georgeore
georgeore

...Yeh!...that's....great....!? Uh....why....would I want to dot that?....Hmmmm.

tonyfriendly
tonyfriendly

Excellent tip! This is especially good when having to sending info to tech support halfway around the world.

frank_s
frank_s

Those of you who are pointing out that you can redirect command line output to a file are probably preaching to the choir. Most of the posters here probably know that already. But have you ever considered you might want the output someplace other than a plain text file and clip.exe would help with that?

mrjeff99
mrjeff99

what creates the vertical bar shown in the syntax?

dsr
dsr

I suppose you are piping the command to the clipboard so you can later paste it into a file. A better way is to use the ">" and ">>" redirection commands, which will put your output directly into the file. For example: dir > \foo.txt notepad \foo.txt If you use ">" it will create or overwrite the file; if you use ">>" it will create the file or append to it.

arcov
arcov

Good tip always found the Mark option annoying Works in Vista as well, it even has the clip.exe installed

chrisbedford
chrisbedford

Even if it was technically illegal, who cares enough to enforce it? Who is going to police such trivia? But more to the point, do you think Microsoft really cares if you copy minor OS utilities from one version of Windows to another that they neglected to include it with? I don't think so. It may violate the letter but not the spirit of your EULA - they provide so many free utilities for download from their website that this could be considered just a minor extension of that spirit of enablement.

Mike
Mike

The website for commandxpress looks like the product helps with commands, switches, redirection, etc. But doesn't show a copy to clipboard.

Horace999
Horace999

Redirections have their place, but you'd then have to insert the output file into the document (or email) you're working on. Further, the select-&-paste thing gets useless quickly when the output exceeds 3 or so screens, *** and especially *** if the output width exceeds the "DOS" window width. In this case, the pasted text has carriage returns where each line wrapped.

k9opo
k9opo

Click the C: icon in the upper left corner of command prompt window, or right-click anywhere on the title bar, select Properties. On the Options tab, under Edit Options, make sure the QuickEdit Mode box is checked. Exit, saving the properties. Now all you have to do is select what you want copied to the Clipboard with the mouse, and right-click the selection. You can paste it back into the command window with another right-click, or go to another application and do a normal Paste.

sahaia
sahaia

To Accomplish "CTRL-C" in DOS/Command window 1. Right Click and click "Mark" 2. Select the text to be copied. 3. Press Enter Now Paste ("CTRL-V") whereever you want. I have been using this in XP and Vista.

NickNielsen
NickNielsen

is located on the uppercase "\" (just above the key on most modern keyboards). Press \ to get |.

mjohnson
mjohnson

Can you redirect the output to any directory

pjboyles
pjboyles

Single line... Dir >C:\temp\myfile.lst&&Notepad C:\temp\myfile.lst

rhgarne1
rhgarne1

This method is right on the money and so easy! "Ipconfig /all > ipconfig.txt" and open it up with notepad... Kinda figured most everyone used this method!

vaughanm
vaughanm

Well thats how I output from command streight to a txt file, no need to download any extra software when the commands you need are in the dos window, man I have been using redirected output since dos without microsoft's menu program (aka windows)

rcopple
rcopple

Thanks. Thanks also to soon_a for the Edit/Select All > Copy tip. Maybe old, but new to me.

soon_a
soon_a

Click on the c:\ icon at the top left of the command prompt window, click on EDIT > SELECT ALL. Then control-C and then control-V to any editor.

mdphoenix
mdphoenix

It's an excellent tip. I don't always want to create a file when redirecting output. I had no idea of the clip.exe program. I hate people who bash. It's a great tip. We've all been redirecting text to text files since DOS 3.3 (and earlier, I'm sure), what's with the, "Oh man, I've been doing this for ages". Shut up. It's a GREAT tip. I've been doing IT for 17 years and I didn't know about clip.exe.

Pedro.V
Pedro.V

so it's just a question of selecting and right-clicking but it's a good tip none the less, I'm thinking more of large 'walls of text' outputs that are a nightmare to go selecting.

Mike
Mike

when the output exceeds 3 or so screens yes it means you will have to go to redirection. But if the output is smaller then you are having to output to a text file then to put the portion (or all) of the text into a windows program (which is the porpuse of the program) you again have to copy and paste to do that. Yes, s may be injected into the copied text but those can be removed if need be. But s can also injected into the text file.

Oldcrow54
Oldcrow54

On US-market keyboards this may be the case, but having seen modern keyboards used in other countries, I know you can not globally make this assumption. Some keys we take for granted here in the US, require some real gymnastics to get to on non-US market keyboards. In fact, I had to perform some of those same gymnastics to get to a character that only required the additional use of the shift key. I recall having to use the [Alt][GR][some key] to get what I wanted. Plus some of our standard characters are located on different keys in little tiny type. This Wikipedia article does a pretty good job at showing what I'm talking about:

mark
mark

Redirection can be accomplished with the greater than sign. For example: IPCONFIG / ALL > C:\Config_Notes\IPConfig_Result.txt Any valid path will be accepted - as long as there are no spaces in the path and file name. You have two options on the redirect - a single greater than sign " > " is a destructive redirect and creates a new file with the specified name. Two greater than signs " >> " is an append redirect, and will append the results of this command to the existing file.

egpor95
egpor95

I use a notepad replacement called notetab. In addition to being able to open multiple text files in tabs at one time, it has a clipboard feature. When clipboard is turned on, anything copied to the clipboard is automatically pasted into the open text file with clipboard activated. Thus, dir | clip will automatically place the directory listing in the document with no other intervention. This is great if you have a number of outputs to copy. And Clip.exe works with XP Multimedia edition as well.

jerungkun
jerungkun

Yes dude, I've been using that trick for so long since the earlier Windows. Anyway, I just wanna tell beginners who might not realize that they can also get the DOS output to notepad without using extra tools like Clip.exe.

timmartin370
timmartin370

The DOS pipe command would place the file in some not-so-helpful places if you were not careful. It was annoying when that happened.

paul.eggers
paul.eggers

There was a redirect from the command prompt that would go directly to the printer. Does that still work? (I tried it but it didn't work, so I must be doing it wrong.)

Oldcrow54
Oldcrow54

Make sure your command window's buffer is large enough for the output from your activity otherwise you'll only get the last buffersize characters. I commonly default my buffer height to 8192 and my width to whatever size fits without a scroll bar. Make sure you check the "Modify shortcut that started this window" button before closing the windows properties.

ewingdweller
ewingdweller

In Windows XP (NOT Pro!), I have to right-click on the window's title bar. Then, choose 1. Select All; 2. Right-click and choose Copy; and 3, in notepad (or other program), paste the text in. Otherwise, it doesn't seem to copy the window's text.

vaughanm
vaughanm

mdphoenix looks like you do not like people having freedom of speech, well we can all be like that. I WAS NOT BASHING YOU AMERICAN TWIT!!! where I come from we can chose to say it how we see it and how I see it is that you need to sort your shit out and stop flaming people and learn the difference between bashing and a comment.

info
info

I like this tip!!! I work work with so many clients with problems. Very few are related and I do not have time to play with OSs. Tips are great especially from those who are dedicated. Bashers, either say nothing or create a complainer site. Science is about learning and sharing. Keep up the sharing.

chrisbedford
chrisbedford

...is off by default in W2K, and one of the sillier defaults from Microsoft. Also one that no-one tells you about, and the name "quickedit" certainly isn't very descriptive. You can also use the right-click menu, edit, copy to send the highlighted part to the clipboard, but if your dexterity skills (and mouse) is anything like mine you have about a 50/50 chance of getting the next menu item down, which is "close", thereby losing all of the last 25 minutes' work! Can be quite frustrating. Overall I still prefer to use as many keyboard shortcuts as possible in whatever flavour of Windows I'm using, it is usually *way* faster than moving my hand from keyboard to mouse, finding the cursed cursor, finding where I'm supposed to click, yada yada yada & back to the keyboard again for the next text input. Once you have highlighted what you want to copy to the clipboard, just hit the [Enter] key. Done! To paste back to the command prompt, [Alt] [Space], E, P...

sdtimpson
sdtimpson

Redirection is not gonna work if I want to get it in a doc or pdf file. Clip is faster and cleaner no residual files laying around. Steve

NickNielsen
NickNielsen

By default, the current directory on the current drive. I learned early on to preface all pipe output with "C:\".

marka
marka

It does as long as you have either a mapped network printer or an attached printer. USB printers don't work printing to lpt1:

chrisbedford
chrisbedford

-------- In Windows XP (NOT Pro!), -------- Yip it works in Pro too -------- I have to right-click -------- Or left-click on the actual mini-icon "C:\_", that works too -------- on the window's title bar. Then, choose 1. Select All; 2. Right-click and choose Copy; -------- You could also just press Enter at this point instead of right-click & copy. To make above work, on the title bar, right-click and select "Properties". On the Options tab, select "Quickedit". I also like to increase the size of the virtual DOS machine screen by going to the Layout tab and setting Screen Size to at least 43 lines and Screen Buffer to at least 300 lines. When I close the Properties page I always select to keep those properties for all subsequent uses of the shortcut.

FXEF
FXEF

Select All > Ctrl + C works in XP Home SP2. Windows command prompt is real slouch. I guess I've spoiled myself with the Linux X-Terminal.

tom
tom

While I also didn't see your initial response as bashing, I'm very curious why you felt you needed to add the word AMERICAN. As far as I can see, it doesn't add anything, just a disparage against Americans. I'd wonder the same thing if you'd added any other nationality. Just seems petty and unnecessary.

hellspawn_rj
hellspawn_rj

Redirecting to a file is an old trick. Redirecting to the clipboard is NOT an old trick Pasting an output from the command prompt in the middle of a document (ie file list/ program output) would require opening that txt file in notepad and copying it and pasting it in the document you are working on as "your style" suggests. Clip.exe does NOT require you to open the txt file and directly copies it in the clipboard. That is what the article is about. Not redirecting to a file. We'll "get over" it when you finally "get it"

vaughanm
vaughanm

So you don't like my style, thats not my problem. How about you go and build a bridge and get over it. As for everyone else, it is your choice if you perfer to download clip.exe like I did to see how it works or to use redirection to a .txt file. Either way has its advantages, clip goes streight to your clip board and then in to the file you need it in, where as redirection goes to a txt file of your choice, a new one or appended on to an already existing file.

Endoscopy
Endoscopy

It is not so much the information he said but how he said it. This is a different place to put the redirection that many people didn't know. He basically dismissed it because he prefers his method. His dismissal is the bashing. This method bypasses the need to open a new window and cutting and pasting the text out of that file into the document you are working on.

mousebooster
mousebooster

Can't understand the foolish bashing discussion.

Editor's Picks