我正在制作一个批处理脚本,并在谷歌上搜索了如何将命令的输出放入变量中,但这段代码获取了整个输出,因为我只需要冒号之前的前4位数字。(就我而言(
以下是debug.exe的输出示例:
0ADE:0AC0
因此,在这种情况下,myvar的值应该是0ADE。这是代码:
for /f "tokens=* usebackq" %%a in (`echo s 100 8000 74 00 5c 00 4f`) do (set myvar=%%a)
我想我可能需要delims参数,但不知道如何使用它,因为批量就是这样。
EDIT:如果我理解得很好,你只需要剪下一个字符串。如果是这种情况,请在上一个变量集中使用":~0,0",其中每个0代表一个索引位置。E.G:以下每一行都将键入"Hello world!">
set random=Hello world!
echo %random%
echo %random:~0,5% world!
echo Hello %random:~6%
关于"debug.exe"的结果,也许您可以将其结果管道传输到一个临时文件,在批处理中调用它,然后剪切结果。
由于您没有共享足够的代码,我无法为您提供适当的帮助,但我会建议如下:
@echo off
rem This will start debug.exe, and let's hope it allows to pipe the result to a file, as it does not always works.
start "" do.exe > "%temp%log_file_debug.txt"
rem Wait until the output file is written.
echo Press any key once the application is finished.
pause > nul
rem Now lets retrieve the results from the previous file, and hope it have this format: 0ADE:0AC0
for /f "tokens=*" %%c in ('type "%temp%log_file_debug.txt"') do set results=%%~c
rem As we have retrieved the results into a variable, let's snip it only for the 4 firts characters
set snip_result=%results:~0,4%
rem Your snipped code is now set in the variable snip_result. Check it out:
echo Check the result: %snip_result%
pause
希望能有所帮助。当做厘米-
我不能在64位窗口上使用调试,所以未经测试:
@Echo off
for /f "delims=:" %%a in ('
echo s 100 8000 74 00 5c 00 4f^|debug.exe file.dll
') do set "myvar=%%a"
或者准备一个用于调试的输入文件,该文件还包含一个exit/quit命令。