求助:DOS中ping的返回值
------ CODE -------------------------------------------------
@echo off
title "Print PC Hostname"
color A
setlocal enabledelayedexpansion
for /L %%i in (193,1,193) do (
for /L %%j in (7,1,7) do (
set a=172.17.%%i.%%j
echo !a!
ping -n 1 !a!
echo %errorlevel%
)
)
ping -n 1 172.17.193.7
echo %errorlevel%
pause
-------------------------------------------------------------
---- 运行结果 -----------------------------------------------
172.17.193.7
Pinging 172.17.193.7 with 32 bytes of data:
Request timed out.
Ping statistics for 172.17.193.7:
Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
0
Pinging 172.17.193.7 with 32 bytes of data:
Request timed out.
Ping statistics for 172.17.193.7:
Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
1
请按任意键继续. . .
-------------------------------------------------------------
for循环中ping的返回值是:0,而在外面返回是:1。 哪位大侠知道原因?多谢!
------ CODE -------------------------------------------------
@echo off
title "Print PC Hostname"
color A
for /L %%i in (193,1,193) do (
for /L %%j in (7,1,7) do (
ping -n 1 172.17.193.7
echo %errorlevel%
)
)
ping -n 1 172.17.193.7
echo %errorlevel%
pause
-------------------------------------------------------------
---- 运行结果 -----------------------------------------------
Pinging 172.17.193.7 with 32 bytes of data:
Request timed out.
Ping statistics for 172.17.193.7:
Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
0
Pinging 172.17.193.7 with 32 bytes of data:
Request timed out.
Ping statistics for 172.17.193.7:
Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
1
请按任意键继续. . .
-------------------------------------------------------------
刚开始以为是:setlocal enabledelayedexpansion的问题,注释掉后重试,结果还是这样?