📜  实时输出子进程 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:08.189000             🧑  作者: Mango

代码示例1
import subprocess
import sys

process = subprocess.Popen(cmdCommand, shell = True,bufsize = 1,
                           stdout=subprocess.PIPE, stderr = subprocess.STDOUT,encoding='utf-8', errors = 'replace' ) 
while True:
    realtime_output = process.stdout.readline()
    if realtime_output == '' and process.poll() is not None:
        break
    if realtime_output:
        print(realtime_output.strip(), flush=False)
        sys.stdout.flush()