Tuesday, June 18, 2013

Copying output to clipboard with Clip.exe

Yesterday I run across a wonderful little utility I had never heard of and I wanted to share it with you. The name of this tiny MS-DOS utility is Clip and what it does is paste what comes down the pipeline to the Clipboard.

Here's how to use it. Just fire a Command Prompt and type whatever command you want to redirect to clipboard followed by a pipe (|) and the 'Clip' command:
  • dir c:\windows | clip
  • ipconfig /all | clip
  • netstat -an | clip
  • echo copy this to clipboard for me | clip
Clip is available on any recent Windows version out-of-box and has no dependency. So it doesn't rely on Perl nor on Powershell as others stated.

It can be used from a Powershell environment though:
  • PS C:\> Get-Process | clip
  • PS C:\> Get-Service | clip
  • PS C:\> Import-Module activedirectory
  • PS C:\> Get-ADComputer | clip
Powerful, isn't it? What it does from a Powershell point of view is to take the output out of the pipeline and put it in the Clipboard. So if we pipe the Clip command to Get-Member to see what kind of object is passed, we see that there is none:

PS C:\> Get-Service | clip | Get-Member
Get-Member : No object has been specified to the get-member cmdlet.
At line:1 char:32
+ Get-Service | clip | Get-Member <<<<
    + CategoryInfo          : CloseError: (:) [Get-Member], InvalidOperationEx
   ception
    + FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Command
   s.GetMemberCommand

This is the same thing that happen with Write-Host, where no object makes it to Get-Member:

PS C:\> Get-Process | Write-Host | Get-Member

That's all for Clip!

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...