批处理文件中的比较结果不正确


2

这批:

@echo off
set _ping_cmd=ping -n 1 192.168.1.1

FOR /L %%G IN (1,1,60) DO (

    FOR /f "tokens=4 delims=(=" %%G IN ('%_ping_cmd% ^|find "loss"') DO (
        echo Result is [%%G]
        IF  %%G == " 0 " GOTO ON
    )
    timeout 60
)

:ON

产生了这个输出:

D:\>live

Result is [ 0 ]

Waiting for 52 seconds, press a key to continue ...

为什么?显然,%%GIS " 0 ",但goto没有执行..


您正在为两个FOR调用重用相同的变量名称。这是在惹麻烦。
肖恩

Answers:


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.