我有以下代码,我基本上试图比较批处理文件中的2个整数(其中一个是从注册表中检索的) -
set mainCounter=1
reg add HKLM\Software\Looptest /f /v mainCounter1 /t REG_SZ /d 0
rem ---- some code here ---
FOR /f "tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Looptest" /v "mainCounter1"') do set "mainCounter1=%%b"
echo mainCounter :: %mainCounter%
echo mainCounter1 :: %mainCounter1%
if %mainCounter% EQU %mainCounter1% goto _reImageSystem
:_reImageSystem
echo mainCounter while reimaging :: %mainCounter%
echo mainCounter1 while reimaging :: %mainCounter1%
pause
此代码清楚地表明,mainCounter的值为1(手动设置)
和,
mainCounter1的值设置为registry ..为0。
不过,当我比较if %mainCounter% EQU %mainCounter1% goto _reImageSystem
时,显然它不应该进入_reImageSystem,但它会......
输出结果为:
mainCounter :: 1
mainCounter1 :: 0
mainCounter while reimaging :: 1
mainCounter1 while reimaging :: 0
所以,可能比较不起作用..
if %mainCounter% EQU %mainCounter1% goto _reImageSystem
有什么建议吗?
谢谢!
答案 0 :(得分:1)
如果比较为假,它仍然通过落到标签上并执行。
为了防止这个分支:
if %mainCounter% EQU %mainCounter1% goto _reImageSystem
goto end
:_reImageSystem
bla bla
bla bla
:end
(或GOTO:eof
结束或反转您的逻辑并使用{{1}})