Windows utility/tool command line to move clipboard to file
Welcome to Programming Tutorial official website. Today - we are going to cover how to solve / find the solution of this error Windows utility/tool command line to move clipboard to file on this date .
I have seen a similar tool CLIP here Clip command but it works into clipboard not the other direction.
I have seen references to “paste” but this doesnt appear to be part of windows. I need to find a solution that works with standard w7 w8 w10 environments.
Clip is distributed. Does anybody a tool that works from clipboard to file?
EDIT Seems it might be possible to do with a powershell command
This C# program I just wrote does what I would to do with a Powershell
class Clip2File { [STAThread()] static void Main(string[] args) { var fileName = @"c:demo.png"; if (args.Length != 0){ fileName = args[0]; } if (!Clipboard.ContainsImage()) return; Image img = Clipboard.GetImage(); img?.Save(fileName, ImageFormat.Png); } }
Answer
Windows cmd
(if clipboard contains text data):
Powershell -command Add-Type -AssemblyName System.Windows.Forms;[System.Windows.Forms.Clipboard]::GetText()
Example shows that above command adds two bytes to output (Cr and Lf):
==> >1049363a.txt echo first line ==> >>1049363a.txt echo 2nd line ==> clip<1049363a.txt ==> >1049363b.txt Powershell -command Add-Type -AssemblyName System.Windows.Forms;[System.W indows.Forms.Clipboard]::GetText() ==> findstr /N "^" 1049363*.txt 1049363a.txt:1:first line 1049363a.txt:2:2nd line 1049363b.txt:1:first line 1049363b.txt:2:2nd line 1049363b.txt:3: ==> dir 1049363*.txt |find ".txt" 06.03.2016 17:24 22 1049363a.txt 06.03.2016 17:24 24 1049363b.txt ==>
Read more about .NET Framework Clipboard Class methods.
Edit answers extended topic (save image, cf. ImageFormat Class):
Add-Type -AssemblyName System.Windows.Forms ### not necessary in PowerShell_ISE if ($([System.Windows.Forms.Clipboard]::ContainsImage())) { $image = [System.Windows.Forms.Clipboard]::GetImage() $filename='d:testtest.png' ### edit to fit in your circumstances [System.Drawing.Bitmap]$image.Save($filename, [System.Drawing.Imaging.ImageFormat]::Png) Write-Output "clipboard content saved as $filename" } else { Write-Output "clipboard does not contains image data" }