realtime output subprocess

Solutions on MaxInterview for realtime output subprocess by the best coders in the world

showing results for - "realtime output subprocess"
Eleonora
23 Jun 2019
1import subprocess
2import sys
3
4process = subprocess.Popen(cmdCommand, shell = True,bufsize = 1,
5                           stdout=subprocess.PIPE, stderr = subprocess.STDOUT,encoding='utf-8', errors = 'replace' ) 
6while True:
7    realtime_output = process.stdout.readline()
8    if realtime_output == '' and process.poll() is not None:
9        break
10    if realtime_output:
11        print(realtime_output.strip(), flush=False)
12        sys.stdout.flush()