使用python中的子进程模块实时输出终端命令

时间:2020-04-23 17:11:58

标签: python subprocess

我正在尝试使用子流程模块显示实时数据,但是它仅显示第一行。 我试图遵循一些教程。在这里给出

read subprocess stdout line by line

我尝试过的代码

import subprocess
proc = subprocess.Popen(
    ['aria2c', 'http://cdimage.deepin.com/releases/20Beta/deepin-20Beta-desktop-amd64.iso'], stdout=subprocess.PIPE)
while True:
    line = proc.stdout.readline()
    if not line:
        break
    # the real code does filtering here
    print("test:", line.rstrip())

实际输出

Display only one line

预期产量

display all the informations

0 个答案:

没有答案
相关问题