This page is edited from the 1cmdfaq.txt faq-file contained in
my tscmd.zip
command line interface (CLI) collection. That zipped file has much
additional material, including a number of detached .cmd script
files. It is recommended that you also get the zipped version as a
companion.
Please see "
The Description and
the Index page" for the conditions of usage and other such
information.
67} Is it possible to send a script variable value to the clipboard?
Get CLIP.EXE from the
Windows98 Resource Kit at
if it still is available or copy a more recent version from Windows
Server 2003's C:\%windir%\system32 folder. Windows 7 and 10 (64-bit)
have a clip.exe, but they are not valid on a regular XP. However,
the first two are.
@echo off & setlocal enableextensions disabledelayedexpansion
set find_=clip.exe
set found_=
for %%f in ("%find_%") do set found_="%%~$PATH:f"
if exist "%find_%" set found_="%find_%"
if [%found_%]==[""] (
echo "%find_%" not found at path or in the current folder
goto :EOF)
::
if not "%~1"=="" goto _clip
echo Usage: %~0 "Your text"
goto :EOF
::
:_clip
echo %~1|clip
endlocal & goto :EOF
To see what is on the clipboard call
C:\WINDOWS\system32\clipbrd.exe
However, the above produces an end of line, so the clipboard actually
contains the above text
and and an empty
line. To avoid that replace
echo %~1|clip
with
set /p="%~1"<nul|clip
as per
item #15.
Consider one potential application. Send the date and time to the
clipboard. Assumes %time% as H:MM:SS.ss
@echo off & setlocal enableextensions
set time_=0%time:~0,-6%
set time_=%time_:~-5%
set /p datetime="%date% %time_:~0,5%"<nul|clip
endlocal & goto :EOF
For two real applications of (optionally) sending material to
clipboard see
FULLNAME.CMD and
GETFDATE.CMD.
There are other utilities to transfer date between the command line
window and the clipboard. These include from GNU
UnxUtils.zip
gclip.exe Get Windows clipboard text from stdin
pclip.exe Put the Windows clipboard text to stdout
and
clipboard.zip Command Line Clipboard Access software by Steve Kemp.