Read streaming input from subprocess.communicate()

后端 未结 7 910
攒了一身酷
攒了一身酷 2020-11-21 05:53

I\'m using Python\'s subprocess.communicate() to read stdout from a process that runs for about a minute.

How can I print out each line of that process

7条回答
  •  清酒与你
    2020-11-21 06:00

    If you want a non-blocking approach, don't use process.communicate(). If you set the subprocess.Popen() argument stdout to PIPE, you can read from process.stdout and check if the process still runs using process.poll().

提交回复
热议问题