找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 21295|回复: 2

[文本处理] Ping命令返回碼ERRORLEVEL問題

[复制链接]
发表于 2012-8-31 12:16:22 | 显示全部楼层 |阅读模式
1,在CMD窗口下,直接運行命令ping 192.168.0.1  然後用ECHO %ERRORLEVEL%查看,如果ping通,返回碼為0;ping不同,返回碼為1;

  2, 但是放在*.BAT文件中直接運行,不管通不通,返回碼都是0。

請教大蝦,爲什麽
发表于 2012-8-31 17:16:32 | 显示全部楼层
同求方法。。。。学习中。。。
发表于 2012-8-31 20:59:53 | 显示全部楼层
我怎么没有出现这个现象?
  1. @echo off
  2. ::我的网关是192.168.1.1
  3. ::下面是成功的:
  4. ping 192.168.1.1
  5. echo %errorlevel%
  6. ::下面是失败的:
  7. ping 192.168.2.1
  8. echo %errorlevel%
  9. pause
复制代码
结果是:

Pinging 192.168.1.1 with 32 bytes of data:

Reply from 192.168.1.1: bytes=32 time=8ms TTL=64
Reply from 192.168.1.1: bytes=32 time<1ms TTL=64
Reply from 192.168.1.1: bytes=32 time<1ms TTL=64
Reply from 192.168.1.1: bytes=32 time<1ms TTL=64

Ping statistics for 192.168.1.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 8ms, Average = 2ms
0

Pinging 192.168.2.1 with 32 bytes of data:

Request timed out.
Request timed out.
Request timed out.
Request timed out.

Ping statistics for 192.168.2.1:
    Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
1
请按任意键继续. . .
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-19 15:34 , Processed in 0.016507 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表