Python2.7版本,想调用subprocess获取iperf server端的输出,但打印stdout一直为None
serverCMD = 'iperf.exe -s -i 1 -w 2M'
process = subprocess.Popen(serverCMD)
time.sleep(50)#在client端时间设置跑5s
process.terminate()#调用此函数是因为即使跑了5s,iperf进程也不会退出,除非手动杀掉
print '=============='
print process.stdout
print '=============='
结果是:
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 2.00 MByte
------------------------------------------------------------
[ 4] local 192.168.1.64 port 5001 connected with 192.168.1.68 port 64703
[ 5] local 192.168.1.64 port 5001 connected with 192.168.1.68 port 64704
[ ID] Interval Transfer Bandwidth
[ 5] 0.0- 1.0 sec 1.84 MBytes 15.5 Mbits/sec
[ 4] 0.0- 1.0 sec 1.24 MBytes 10.4 Mbits/sec
[SUM] 0.0- 1.0 sec 3.08 MBytes 25.8 Mbits/sec
[ 4] 1.0- 2.0 sec 1.62 MBytes 13.6 Mbits/sec
[ 5] 1.0- 2.0 sec 2.88 MBytes 24.2 Mbits/sec
[SUM] 1.0- 2.0 sec 4.50 MBytes 37.8 Mbits/sec
[ 5] 2.0- 3.0 sec 4.17 MBytes 35.0 Mbits/sec
[ 4] 2.0- 3.0 sec 3.27 MBytes 27.4 Mbits/sec
[SUM] 2.0- 3.0 sec 7.44 MBytes 62.4 Mbits/sec
[ 5] 3.0- 4.0 sec 4.95 MBytes 41.5 Mbits/sec
[ 4] 3.0- 4.0 sec 4.88 MBytes 40.9 Mbits/sec
[SUM] 3.0- 4.0 sec 9.83 MBytes 82.4 Mbits/sec
[ 4] 4.0- 5.0 sec 2.44 MBytes 20.5 Mbits/sec
[ 5] 4.0- 5.0 sec 2.03 MBytes 17.0 Mbits/sec
[SUM] 4.0- 5.0 sec 4.47 MBytes 37.5 Mbits/sec
[ 4] 0.0- 5.5 sec 15.5 MBytes 23.5 Mbits/sec
[ 5] 0.0- 5.6 sec 18.1 MBytes 27.4 Mbits/sec
[SUM] 0.0- 5.6 sec 33.6 MBytes 50.8 Mbits/sec
==============
None
==============
在client端,因为跑完了设定的时间,iperf进程会自动退出,所以用subprocess.check_output()获取到了想要的结果,
但iperf server这边因为即使跑完了设置的时间,iperf进程也不会自动退出,所以用check_output()得不到想要的子进程输出.只能用Popen.但用process.stdout还是得不到子进程的输出(None),哪位大神能给指点一下..万分感激