Clipboard Access from Windows Batch Files

Writing to the clipboard

The clip.exe utility ships with Windows and accepts piped input from any command. A batch file can send variable contents or command output to the clipboard with a line such as echo %VAR% | clip. The command replaces the current clipboard contents with the piped stream and returns immediately.

Reading from the clipboard

Batch has no native read command for clipboard data. The reliable pattern invokes PowerShell inline: powershell -command "Get-Clipboard". Capture the result with a for /f loop to assign it to a variable for further processing. This works on Windows 10 and later where PowerShell is present by default.

Practical considerations

Scripts that hand off data to GUI applications or collect user-copied text can stay in pure batch without external dependencies. The PowerShell call adds negligible overhead for occasional use. For high-frequency loops consider caching the clipboard value or using a compiled helper. Test the PowerShell invocation on the target OS version before deploying; older builds may require the .NET clipboard class instead of the Get-Clipboard cmdlet.

Back to the blog index