在批处理脚本中使用FOR时遇到问题。
我的批处理文件包含以下内容:
Echo off
set max_page=2
for /l %%i IN (1,1,%max_page%) do (
echo.
echo Page %%i off %max_page%
echo ========================================================
echo page %%i
:find_server
set "result=true"
echo page %%i
wget -S --spider -t 1 http://portal/ 2> check_portal.txt
echo page %%i
for /f "skip=1 tokens=4" %%b in ('findstr /L "Connecting" check_portal.txt') do set status=%%b
echo page %%i
if "%status%"=="failed:" set result=false
echo page %%i
if "%result%"=="false" (
goto :find_server
)else goto :server_connected
:server_connected
for /f "skip=3 tokens=2 delims=/" %%c in ('findstr /L "Location: " check_portal.txt') do set server_portal_upd=%%c
echo page %%i
)
pause
结果:
Page 1 off 2
========================================================
page 1
page 1
page 1
page 1
page 1
page %i
Press any key to continue . . .
但如果删除下面的行,则脚本会成功运行
:find_server
set "result=true"
echo page %%i
wget -S --spider -t 1 http://portal/ 2> check_portal.txt
echo page %%i
for /f "skip=1 tokens=4" %%b in ('findstr /L "Connecting" check_portal.txt') do set status=%%b
echo page %%i
if "%status%"=="failed:" set result=false
echo page %%i
if "%result%"=="false" (
goto :find_server
)else goto :server_connected
:server_connected
for /f "skip=3 tokens=2 delims=/" %%c in ('findstr /L "Location: " check_portal.txt') do set server_portal_upd=%%c
为什么Line 8
显示page %i
而非page 1
?
哪里出错了?请纠正我。
非常感谢你的sugesstion
答案 0 :(得分:2)
标签:find_server
等终止for
循环。尝试重组以使用call :subroutineneame
BTW - else
关键字的 两侧必须有空格。