python2.7_调用系统命令Ping

import subprocess  
#import re
p = subprocess.Popen(["ping.exe", 'www.baidu.com'],
  stdin = subprocess.PIPE,
  stdout = subprocess.PIPE,
  stderr = subprocess.PIPE,
  shell = True)  
out = p.stdout.read()  
print 'Result:---- \n'
print out
#以下为正则表达式抓取linux ping结果参考 
#regex = re.compile("Minimum = (\d+)ms, Maximum = (\d+)ms, Average = (\d+)ms", re.IGNORECASE)
#print regex.findall(out)

 

你可能感兴趣的:(python)