Windows Tip Sheet
It’s Hip to Clip
Vista scripters can now get access to the clipboard from the command line.
- By Jeffery Hicks
- 10/03/2007
Windows Vista now includes a command-line utility that lets you access the clipboard. You can easily pipe the results of a command to the clipboard, like this:
C:\ dir c:\windows\system32\*.exe | clip
Instead of displaying all of the executable files to the console, the information is sent to the Windows clipboard. Open up Notepad or any other application, paste and there you go! This isn’t necessarily earth-shattering, since you could easily redirect the output to a text file. But what if you didn’t want a text file? Or you wanted to save several items to the clipboard? If you use Clip while a Microsoft Office application is open, each copied block can be retrieved by Office clipboard which, by default, saves the last 24 copies.
If you want to copy the contents of a text file to the clipboard, you could do this:
C:\ type c:\files\servers.txt | clip
or you can use console redirection:
C:\ clip < c:\files\servers.txt
Tech HelpJust An
E-Mail Away |
Got a Windows, Exchange or virtualization question
or need troubleshooting help? Or maybe you want a better
explanation than provided in the manuals? Describe
your dilemma in an e-mail to the MCPmag.com editors
at [email protected];
the best questions get answered in this column and garner
the questioner with a nifty Redmond T-shirt.
When you send your questions, please include your
full first and last name, location, certifications (if
any) with your message. (If you prefer to remain anonymous,
specify this in your message, but submit the requested
information for verification purposes.) |
|
|
In both cases, the contents of servers.txt is placed in the clipboard. This also comes in handy as a poor man’s automated signature. There are a few forums I frequent that don’t provide any support for signature blocks. I can use a batch file or DOSKEY command for the following to get the copy of my signature, which I can then paste into my forum post:
C:\ clip < %userprofile%\documents\sig.txt
In case you didn't know: You can achieve similar functionality in Windows PowerShell by installing the PowerShell Community Extensions. There is a clipboard cmdlet you can use in almost the same manner.
About the Author
Jeffery Hicks is an IT veteran with over 25 years of experience, much of it spent as an IT infrastructure consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He is a multi-year recipient of the Microsoft MVP Award in Windows PowerShell. He works today as an independent author, trainer and consultant. Jeff has written for numerous online sites and print publications, is a contributing editor at Petri.com, and a frequent speaker at technology conferences and user groups.