Constantly print Subprocess output while process is running

后端 未结 13 808
庸人自扰
庸人自扰 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:48

    To answer the original question, the best way IMO is just redirecting subprocess stdout directly to your program's stdout (optionally, the same can be done for stderr, as in example below)

    p = Popen(cmd, stdout=sys.stdout, stderr=sys.stderr)
    p.communicate()
    

提交回复
热议问题