Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear Windows clipboard using a batch file or PowerShell?

I have a batch file and my program works automatically with the clipboard.

But I want to clear the clipboard and used this:

echo>nul|clip

Is there any other method for clearing Windows clipboard?


2 Answers

Here is another way to do it. This appears to clear at least CF_TEXT and CF_BITMAP. Needs testing to see if it clears all CF_* types.

powershell -NoLogo -NoProfile -Command "Set-Clipboard -Value $null"
like image 77
lit Avatar answered Jan 26 '26 08:01

lit


Well, the most logical approach (at least in my opinion), that is to redirect (<) nothing (nul) to STDIN (handle 0) to the clip command, like < nul clip, does not work due to a terrible design of that command, because it seems that input redirection (<) can only be done with files.

So a pipe (|) needs to be used, which still allows several ways:

echo/> nul | clip

break | clip

(rem/) | clip

type nul | clip

goto | clip

call | clip

exit | clip

All of the above methods use a command on the left side of the pipe that do not output anything to STDOUT (handle 1).

like image 23
aschipfl Avatar answered Jan 26 '26 07:01

aschipfl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!