I was browsing the Windows Server Command Line Reference today and came across clip.exe. I was not familiar with this little utility, but after a brief investigation I found that it could redirect command line output to the Windows clipboard.
Why would I want to do this?
I’m very command line oriented. I grew up with DOS, so I do as much through the command line as possible, especially when it comes to repetative tasks that can be scripted.
For example, a task I may perform is to list all instances of Java on my drive and redirect the output to a text file so I could easily read it, especially if there was a large number of files. To do this, I’d type
dir java.exe /s >java.txt
I’d then have to go find the java.txt output file and open it with a text editor. Not a big deal in this case, but imagine working 7 or 8 subdirectories deep and having to browse to the file. Again, not a daunting task, but it still takes mouse clicks.
A better way to perform this task is to use clip.exe to pipe the output to the Windows clipboard. To do so, you’d type:
dir java.exe /s |clip
Now I can open up notepad and paste the output by pressing ctrl-v.
Clip.exe can be found on a Windows 2003 server in the c:\windows\system32 directory. If you don’t have access to a Windows 2003 server, you can download it here and save it to your c:\windows\system32 directory.
If you’d like to do the opposite operation, i.e. copy the contents of the clipboard to the command line, perform the following steps:
Highlight the text to be copied to the clipboard by highlighting it and press ctrl-c
Press Windows key+R, type cmd and hit enter to open a command prompt
Press Alt+Space Bar to open the window’s Titlebar menu
press ‘e‘, ‘p‘ (without the comma or quotes) to open the edit menu and paste the contents of the clipboard.