Programming Field

Clip - DOS/Command Prompt Reference

[Windows Vista or later] Copies the data the Clip program receives as input to the Windows clipboard.

Syntax

clip[.exe] < <file-name>
<any-command> | clip[.exe]
< <file-name> Using input redirection with <file-name> as specified, it takes the data from the file as input for Clip. As a result, the data from the file is copied to the clipboard.
<any-command> | Using pipes and specifying <any-command>, it takes the output of the specified command as input for Clip. As a result, the output content of the command is copied to the clipboard.

Details

Usage of Clip

In the Command Prompt, you can copy the content displayed on the screen to the clipboard by selecting "Mark" from the menu. However, by redirecting the output content as input to Clip, you can copy to the clipboard without using mouse operations. Keep in mind that if there is already some data in the clipboard, it will be discarded before copying. Therefore, even if you call Clip multiple times, only the input provided in the last call will be copied to the clipboard.

* The input (standard input) received by Clip is ensured to be something other than keyboard input on the console. If Clip is executed without pipes or input redirection, it will output the usage of Clip.

Samples

Sample 1

type CON | clip

Copies the input from the keyboard to the clipboard. To finish the input, you need to enter only Ctrl+Z on an empty line, so the copied text will always have a newline character at the end.

Note that when executing Clip as a standalone command without using pipes or redirects, it will display a message about the usage of Clip. Therefore, it is necessary to pass input using ‘type CON’ and pipe like ‘type CON | clip’.

* If you use ‘clip < CON’, standard input becomes keyboard input, and the message regarding the usage of Clip will be displayed.

Sample 2

set /P MY_TMP="Hoge" < NUL | clip

Copies the string "Hoge" without including a newline character to the clipboard. By using ‘set /P’ for screen output, which does not include a newline character, you can pass this output to Clip, allowing you to copy without including a newline character.

Sample 3 (Batch file)

@echo off
setlocal enableextensions
call :MyProcess C D E > mytemp.dat
clip < mytemp.dat
erase mytemp.dat
exit /b 0

:MyProcess
    if "%1"=="" exit /b 0
    mycheck.exe %1
    shift
    goto MyProcess

[Extensions] Copies a series of outputs executed within the label ‘MyProcess’ in a batch file to the clipboard. Since pipes cannot be used with the Call command that invokes labels in batch files, copying is done via a temporary file using output redirection and input redirection.

See also