[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

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

1,在CMD窗口下,直接運行命令ping 192.168.0.1  然後用ECHO %ERRORLEVEL%查看,如果ping通,返回碼為0;ping不同,返回碼為1;

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

請教大蝦,爲什麽

同求方法。。。。学习中。。。

TOP

我怎么没有出现这个现象?
  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
请按任意键继续. . .
时光荏苒||新陈代谢&&涛声依旧||本性难移

TOP

返回列表