- 论坛徽章:
- 0
|
可能标题写的有点不清楚,具体情况如下:
写一个程序,能获得程序输出,并且在程序执行完毕之后,能获知。程序如下- import subprocess
- pp = subprocess.Popen('ping -c4 www.google.cn', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
- while 1:
- line = pp.stdout.readline()
- print('out-->'+line+'<')
- if subprocess.Popen.poll(pp)==0:
- break
- print('DONE')
复制代码 实际执行的效果有2种情况
第一种
out-->PING www.google.cn (203.208.45.212) 56(84) bytes of data.<
out-->64 bytes from 203.208.45.212: icmp_seq=1 ttl=55 time=4.03 ms<
out-->64 bytes from 203.208.45.212: icmp_seq=2 ttl=55 time=3.18 ms<
out-->64 bytes from 203.208.45.212: icmp_seq=3 ttl=55 time=3.90 ms<
out-->64 bytes from 203.208.45.212: icmp_seq=4 ttl=55 time=4.47 ms<
DONE
---------------------------
第二种
out-->PING www.google.cn (203.208.46.212) 56(84) bytes of data.<
out-->64 bytes from 203.208.46.212: icmp_seq=1 ttl=54 time=26.3 ms<
out-->64 bytes from 203.208.46.212: icmp_seq=2 ttl=54 time=3.22 ms<
out-->64 bytes from 203.208.46.212: icmp_seq=3 ttl=54 time=6.95 ms<
out-->64 bytes from 203.208.46.212: icmp_seq=4 ttl=54 time=4.59 ms<
out--><
out-->--- www.google.cn ping statistics ---<
out-->4 packets transmitted, 4 received, 0% packet loss, time 3009ms<
out-->rtt min/avg/max/mdev = 3.225/10.282/26.363/9.380 ms<
out--><
out--><
out--><
out--><
DONE
第一种执行结果占多数,第二种执行结果,有时候会出现。
按照实际执行ping -c4 www.google.cn的情况看,第一种情况少了最后的三行,所以说是不正确的。但是为什么常常是这种情况哪?求版主和各位大大帮忙看看那问题。 |
|