访问从剪贴板和存储复制的文本在批处理文件 [英] Accessing copied text from a clipboard and store in a batch file
问题描述
在这我创造,我想提出两个不同的复制的文本之间的字符串比较该批处理文件。基本上,是旧的复制文本的相同更新的复制的文本。为此,我想访问剪贴板和旧复制的文本保存在我的批处理文件中的变量。然后,将新的文本,将其存储在我的批处理文件中另一个变量,并比较两个,看看它们是否相同。我试图寻找一个解决方案,但所有我见过的文章描述了如何将文本复制到使用批处理文件剪贴板。然而,我试图做相反的事情。所有帮助是极大的AP preciated。
In the batch file that I am creating, I am trying to make a string comparison between two different copied text. Basically, is the old copied text the same as the newer copied text. For this I want to access the clipboard and store the old copied text in a variable inside my batch file. Then, copy the new text, store it in another variable inside my batch file, and compare the two and see if they are the same. I have tried searching for a solution, but all the articles that I have seen describe how to copy text into the clipboard using a batch file. Whereas, I am trying to do the opposite. All help is greatly appreciated.
推荐答案
下面是一个简短和批次嵌入解决方案:
Here is a short and batch embed solution:
1)建立该剪贴板的内容存储在临时文件中的小VB文件
1) create a small VB file which store the content of the clipboard in a temporary file
set clipFile=%temp%\clipboard
set vbFile=%temp%\clipboard.vbs
del %vbFile% %clipFile%
rem Create VB file
>"%vbFile%" (
echo.Set objHTML = CreateObject("htmlfile"^)
echo.ClipboardText = objHTML.ParentWindow.ClipboardData.GetData("text"^)
echo.path = "%clipFile%"
echo.Set objFSO = CreateObject("Scripting.FileSystemObject"^)
echo.Set objFile = objFSO.OpenTextFile(path, 2, true^)
echo.objFile.WriteLine ClipboardText
echo.objFile.Close )>>"%vbFile%"
2)执行VB脚本
2) execute the VB script
"%vbFile%"
3)在一个变量存储文件内容
3) store file content in a variable
SETLOCAL ENABLEDELAYEDEXPANSION
for /f "delims=" %%i in (%clipFile%) do Set line=%%i
set clipboard=!line!
echo clipboard="%clipboard%"
ENDLOCAL
这篇关于访问从剪贴板和存储复制的文本在批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!