标题: [网络连接] [已解决]BAT批处理怎样根据ping返回值运行某程序? [打印本页]
作者: sky743 时间: 2014-5-18 01:33 标题: [已解决]BAT批处理怎样根据ping返回值运行某程序?
本帖最后由 sky743 于 2014-5-19 13:15 编辑
代码如下:- @echo off
- :p
- ping www.baidu.com
- if errorlevel = 1 goto n
- if errorlevel = 0 goto y
- :n
- goto p
- :y
- start 某程序
- exit
复制代码
问题是:
当ping返回Reply from 192.168.1.1: Destination host unreachable时也运行了某程序, 我只想让它ping通www.baidu.com时才运行某程序。
求大神帮忙解决
作者: 522235677 时间: 2014-5-18 02:05
- ping baidu.com -n 1
- if errorlevel 1 (cd.) else (start "" c:\q.exe)
复制代码
作者: sky743 时间: 2014-5-18 08:51
本帖最后由 sky743 于 2014-5-18 09:04 编辑
回复 2# 522235677
谢谢,可还是不行啊!出现Reply from 192.168.1.1: Destination host unreachable后还是运行程序了!
作者: sky743 时间: 2014-5-19 13:18
经过仔细研究,绕个小弯就能解决了!
@echo off
:p
ping -n 1 192.168.1.1 >c:\3.txt
find "字节=32" c:\3.txt >nul
if %errorlevel% == 0 (start c:\1.txt) else (goto p)
WIN7系统测试成功
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |