本批次:
@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 ...
为什么?显然是%%G
IS " 0 "
,但goto
没有执行。
答案1
显然,%%G
IS " 0 "
,但是goto
没有执行。
您需要如下的引号%%G
:
IF "%%G" == " 0 " GOTO ON