【发布时间】:2021-09-25 06:32:22
【问题描述】:
我正在创建一个函数来测试连接并获取价值,但它不起作用。 我正在使用 grep 来获取仅收到的值。
def testConnection(ip):
TIMEOUT = 10
args = ('sudo', 'ping', '-c', '1', '-q', ip, '|', 'grep -E -o', '"[0-9]+ received"', '|', 'cut', '-f1', '-d')
try:
popen = subprocess.Popen(args, stdout=subprocess.PIPE)
popen.wait(timeout=TIMEOUT)
if (popen == 1):
print(ip + " is up")
else:
print(ip + " is down")
except subprocess.TimeoutExpired as e:
print(e)
return False
if(popen.returncode != 0):
raise ServiceException()
【问题讨论】:
标签: python python-3.x django subprocess ip