import subprocess

file_out = subprocess.Popen('ping www.baidu.com', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while True:
line = file_out.stdout.readline()
print(line)
if subprocess.Popen.poll(file_out)==:
break
04-30 19:08