Quick Tips - Piping to Clipboard (Windows)

I came across this neat tip the other day. I needed to capture some text from the command line in Windows. Usually I would just pipe (cmd > filename.txt) the results of whatever command I'm running into a text file. Then I would open the text file afterwards and copy/paste it wherever I needed it. I figured there had to be a more direct way. It turns out, I was correct. Enter "clip.exe" a built in utility that will allow you to pipe command line output directly to your clipboard. So how do you use it? It's really simple. Say for example you need a list of files in a directory. You could run the following and presto it's in your clipboard. Replace dir with whatever command line application you want to capture input from. Run it and copy/paste to your heart's content.

dir | clip

Apparently this has been around in some form or fashion since WIndows 98. It became a regular built in utility in Windows Vista. Not sure why I'm just now finding this out. There are similar tools (xclip) in linux as well. Happy scripting!


Categories: Quick Tips

Tags: command-line