gpt4 book ai didi

python - 如何使用Python子进程模块从Linux终端读取数据

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:19:40 25 4
gpt4 key购买 nike

<分区>

到目前为止,这是我的代码:

import subprocess


def __init__(pingcount, hostname):

try:
out, error = subprocess.Popen.communicate(subprocess.Popen("ping -n " + pingcount + ' ' + hostname), timeout=10)
except subprocess.TimeoutExpired:
subprocess.Popen.kill(subprocess.Popen)
return "No connection to terminal. Contact system administrator."

print(str(out))

if str(out).find("rtt") != -1:
return str(out)[str(out).find("rtt"):]
else:
return "No connection to server."

类似的代码适用于 Windows,但在调用此函数时,我得到的返回值是 None

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com