【发布时间】:2015-09-16 21:03:28
【问题描述】:
所以我是 Python 中的菜鸟,这很痛苦,但我正试图想出一种方法来 PING 一个站点,然后吐出一个“if/else”子句。
到目前为止,我有这个:
import subprocess
command = "ping -c 3 www.google.com" # the shell command
process = subprocess.Popen(command, stdout=subprocess.PIPE,
stderr=None, shell=True)
#Launch the shell command:
output = process.communicate()
print output[0]
下面是我出错的地方,这是第二部分:
if output == 0.00
print "server is good"
else
print "server is hosed"
显然第 2 部分没有成功。
我的问题是,我如何“读取”来自 ping 的结果(毫秒) icmp_seq=0 ttl=44 时间=13.384 毫秒
并说“如果 ping 时间快于 12.000 毫秒,则执行此操作” 别的 “做那个”
现在我只是在打印,但很快我想改变它,所以其他的东西。
【问题讨论】:
-
为什么不把get请求当作心跳呢?
标签: python subprocess ping