Friday, October 20, 2017

Save STDOUT/STDERR to clipboard (and more)

Summary: How to redirect the STDOUT or STDERR stream to clipboard.
Note to self (mostly), in case I forget the command that would redirect standard output or standard error stream and save it on the clipboard.

Redirect STDOUT to clipboard:
command | clip
Redirect STDERR to clipboard:
command 2>&1 | clip
The following will save the contents of the current directory to the clipboard:
dir | clip
Now, let's try the following:
dir xyz: | clip
The clipboard now will hold something like this:
 Volume in drive C is SYSTEM
 Volume Serial Number is 1234-ABCD

 Directory of C:\Windows\SysWOW64
Now, let's redirect STDERR to clipboard:
dir xyz:2>&1 | clip
The clipboard now will hold something like this:
"xyz:" is not a recognized device.
"xyz:" is not a recognized device.
 Volume in drive C is SYSTEM
 Volume Serial Number is 1234-ABCD

 Directory of C:\Windows\SysWOW64

File Not Found
See also:
Forgotten (but Awesome) Windows Command Prompt Features by Scott Hanselman
How to pipe stderr, and not stdout?

No comments: