0

我尝试了许多描述的方法,但它不适用于我。谁能解释我如何使用子进程在单个 python 脚本中使用它?

iperf -c 10.0.0.1 -i 1 -t 100 | grep -Po '[0-9.]*(?= Mbits/sec)'

4

1 回答 1

0

所以我已经解决了这个问题。这个想法是将这两个命令与不同的子进程一起使用。首先创建进程iperf并将该进程的输出输入到命令stdin的第二个进程中,grep如下所示:

process1 = subprocess.Popen(["iperf","-c", 10.10.0.1],  stdout=subprocess.PIPE)

prrocess2 = subprocess.Popen(["grep", "-Po",[0-9.]*(?= Mbits/sec)], stdin=process1.stdout, stdout=subprocess.PIPE).communicate()[0] 
于 2017-03-09T14:35:02.897 回答