把写代码过程中较好的一些代码做个备份,如下的代码是关于python在windows下实现ping操作并接收返回信息的代码。
import subprocess
import re
p = subprocess.Popen([“ping.exe”, ‘google.com’],
stdin = subprocess.PIPE,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
shell = True)
out = p.stdout.read()
regex = re.compile(“Minimum = (d+)ms, Maximum = (d+)ms, Average = (d+)ms”, re.IGNORECASE)
print regex.findall(out)