<http://www.netikka.net/tsneti/info/tscmd067.htm>
Copyright © 2003-2010 by Prof. Timo Salmi  
Last modified Mon 24-May-2010 19:53:18

 
Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index
 

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 ftp://ftp.microsoft.com/Services/TechNet/samples/PS/Win98/Reskit/FILE or copy a more recent version from Windows Server 2003's C:\%windir%\system32 folder. AFAIK Vista has a clip.exe, but I have no knowledge whether it will work on XP. However, the first two will.

  @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.

References/Comments: (If a Google message link fails try the links within the brackets.)
  clip it
  Where's the Clipboard Viewer in Windows XP?
  Google Groups Jun 7 2008, 11:25 am [M]
  Google Groups Jun 9 2008, 7:13 am [M]
  clipboard.zip