live output from subprocess command

后端 未结 16 1177
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 08:16

I\'m using a python script as a driver for a hydrodynamics code. When it comes time to run the simulation, I use subprocess.Popen to run the code, collect the

16条回答
  •  旧时难觅i
    2020-11-22 09:19

    We can also use the default file iterator for reading stdout instead of using iter construct with readline().

    import subprocess
    import sys
    process = subprocess.Popen(your_command, stdout=subprocess.PIPE)
    for line in process.stdout:
        sys.stdout.write(line)
    

提交回复
热议问题