我有以下这段代码,我基本上试图比较批处理文件中的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有什么建议么 ?
谢谢!
I have this following piece of code where I am basically trying to compare 2 integers in a batch file (one of them is retrieved from registry) -
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% pauseThis code clearly suggests that, value of mainCounter is 1 (set manually) And, The value of mainCounter1 is set to registry.. which is 0. Still , when I compare if %mainCounter% EQU %mainCounter1% goto _reImageSystem , clearly it should not go inside _reImageSystem, but it goes...
The output is:
mainCounter :: 1 mainCounter1 :: 0 mainCounter while reimaging :: 1 mainCounter1 while reimaging :: 0So, possible the comparison is not working..
if %mainCounter% EQU %mainCounter1% goto _reImageSystemAny suggestions ?
Thanks!
最满意答案
如果比较为假,它仍将落入标签并执行。
为了防止这个分支:
if %mainCounter% EQU %mainCounter1% goto _reImageSystem goto end :_reImageSystem bla bla bla bla :end(或GOTO:eof结束或反转你的逻辑并使用NEQ )
If the comparison is false it will still fall through to the label and execute.
To prevent this branch away:
if %mainCounter% EQU %mainCounter1% goto _reImageSystem goto end :_reImageSystem bla bla bla bla :end(Or GOTO:eof to end or invert your logic and use NEQ)
更多推荐
发布评论