How can you get the clipboard contents with a Windows command?

Solution 1:

If you accept to use PowerShell (and not cmd) the you can use Get-Clipboard exactly as you was looking for.

Get-Clipboard > myfile.txt

The adventage of this method is that you have nothing to install.

Note: In place of clip you can use Set-Clipboard that has more options.

Note 2: If you really want to run it from cmd, you can call powershell as in the following example powershell -command "Get-Clipboard | sort | Set-Clipboard".

Solution 2:

You can use the paste.exe software in order to paste text just like you are describing.

http://www.c3scripts.com/tutorials/msdos/paste.html

With it you can do:

paste | command

to paste the contents of the windows clipboard into the input of the specified command prompt

or

paste > filename

to paste the clipboard contents to the specified file.