windowspowershellbatch-filecmdclipboard

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?


Solution

  • 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).