Python2.7版本,想调用subprocess获取iperf server端的输出,但打印stdout一直为None

Hank_Q 2018-02-23 04:41:20
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),哪位大神能给指点一下..万分感激
...全文
1719 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
oyljerry 2018-02-24
  • 打赏
  • 举报
回复
先看看server为什么命令不会退出。

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧