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 Notepad 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 notepad.exe /s > notepad.txt

I’d then have to go find the notepad.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 notepad.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:

  1. Highlight the text to be copied to the clipboard by highlighting it and press CTRL-C.
  2. Press Windows key + R, type cmd and hit enter to open a command prompt.
  3. Press Alt + Space Bar to open the window’s titlebar menu.
  4. Press ‘e‘, ‘p‘ (without the comma or quotes) to open the edit menu and paste the contents of the clipboard.