I am writing a little Python script to log the output and error of another Python program, and simultaneously print them on my screen as usual. This code works well, except it buffers output of the subprocess python program and output them together once for a long time, instead of printing instantly as usual:
subprocess.run(f"python {args.launch} 2>&1 | tee -a {file_path}", shell=True)
in which args.lunch
is the name of my python program and file_path
is the log file. I have tried some existing solutions but none works for me.