Constantly print Subprocess output while process is running

后端 未结 13 826
庸人自扰
庸人自扰 2020-11-22 06:51

To launch programs from my Python-scripts, I\'m using the following method:

def execute(command):
    process = subprocess.Popen(command, shell=True, stdout=s         


        
13条回答
  •  臣服心动
    2020-11-22 07:40

    This works at least in Python3.4

    import subprocess
    
    process = subprocess.Popen(cmd_list, stdout=subprocess.PIPE)
    for line in process.stdout:
        print(line.decode().strip())
    

提交回复
热议问题