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

Matt picture Matt · Jul 23, 2013 · Viewed 49.6k times · Source

For example, I can copy a file to the clipboard like this:

clip < file.txt

(Now the contents of file.txt is in the clipboard.)

How can I do the opposite:

???? > file.txt

So that the contents of the clipboard will be in file.txt?

Answer

Kpym picture Kpym · Dec 1, 2018

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".