【发布时间】:2022-09-23 06:41:06
【问题描述】:
编写一个脚本以从谷歌服务器获取延迟并绘制延迟曲线(在 python 中)我附上了我的试用代码 到目前为止,这是代码:
import subprocess
from subprocess import check_output, Popen, call, PIPE, STDOUT
latency = []
p = Popen(\'ping -n 10 google.com\', stdout = PIPE, stderr = STDOUT, shell = True)
for line in p.stdout:
lntxt = line.decode(\'utf-8\').rstrip()
words = lntxt.split(\' \')
if words[0] == \'Reply\':
print(lntxt)
latency.append(words[4])
print(latency)
使用它的输出应该是这样的: Output
然后问题是用标题和轴绘制延迟曲线
-
问题是什么?
-
您在调用
Popen()时没有使用任何shell 功能,您应该传递一个列表[\'ping\', \'-n\', \'10\', \'google.com\']而没有shell=True -
欢迎来到 SO,我建议您编辑您的问题以说明该程序需要很长时间才能返回并最终打印 []。如果您描述尝试运行代码时发生的情况,您将获得更好的支持。