test.py代码如下:

import urllib2
import sys

try:
    f = urllib2.urlopen('http://www.baidu.com/',timeout = 10)
    f.read(1000)
    f.close()
    print 'success'
    sys.exit(1)

except urllib2.URLError,e:
    print 'fail'
    sys.exit(-1)

使用python test.py运行脚本,然后cmd中输入echo %ERRORLEVEL%查看返回值:

if 正常访问百度:
    返回值为1
else:
    返回值为-1

  

  

相关文章:

  • 2021-08-11
  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-05
  • 2021-09-07
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-29
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案