Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 392
Matt Avatar asked Jul 23 '13 19:07

Matt


People also ask

How do you copy the clipboard command?

Alternatively, right-click anywhere inside the command window, select Mark from the contextual menu, use the mouse to highlight a block text and then press Enter to save it to the clipboard.

How do I use the clip command in Windows?

You can do this by simply typing “ | clip ” after your command. For example if you want to copy “ipconfig” output to notepad then type “ipconfig | clip” & then open a notepad window & simply paste (or Ctrl+V). Sometime these sorts of small things save your valuable time.

How do I get to the PowerShell clipboard?

In Windows PowerShell, if you've used File Explorer to copy a directory to the clipboard (using the regular Copy shortcut-menu command or the Ctrl+C keyboard shortcut), you can access it as System. IO. DirectoryInfo instance by passing -Format FileDropList to Get-Clipboard .


2 Answers

If it would be acceptable to use PowerShell (and not cmd), then you can use Get-Clipboard exactly as you were looking for.

Get-Clipboard > myfile.txt

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

like image 123
Kpym Avatar answered Oct 10 '22 22:10

Kpym


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.

like image 30
Ted Avatar answered Oct 10 '22 21:10

Ted