求助:DOS中ping的返回值

jake20032004 2011-03-21 02:49:26
------ 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的问题,注释掉后重试,结果还是这样?
...全文
159 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Forever_Young 2011-03-21
  • 打赏
  • 举报
回复
你想用这个批处理达到什么要求?
jake20032004 2011-03-21
  • 打赏
  • 举报
回复
在这里发这个帖子没发错吧?

网上貌似有个DOS之家,里面人丁稀少,还限制第一次注册登录30分钟内不需发帖。

估计是怕水军捣乱吧。

6,849

社区成员

发帖
与我相关
我的任务
社区描述
Windows 2016/2012/2008/2003/2000/NT
社区管理员
  • Windows Server社区
  • qishine
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧