#! /usr/bin/python import subprocess import re import sys ip = sys.argv[1] result = subprocess.Popen("fping -C 2 {} | sed -n '$!d'".format(ip), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) result = result.communicate()[1] s = re.match(r'\n.* : (.*) (.*)', result, re.M|re.I) print max(s.groups()) if max(s.groups()) != '-' else 0
python2 subprocess.Popen()获取命令返回结果
最新推荐文章于 2024-07-04 04:29:14 发布