Collecting Stderr In Memory With Subprocess.call
I'm trying to collect stderr in memory, instead of directly writing it to a file or stdout. I do this so I can generated the error log file in a certain way. I found a library call
Solution 1:
stdout = subprocess.check_output(args)
See check_output
documentation for more options.
If you don't want to capture stdout
, use Popen.communicate
:
from subprocess import Popen, PIPE
p = Popen(args, stdout=log_fps["trace"], stderr=PIPE)
_, stderr = p.communicate()
Solution 2:
import subprocess
p = subprocess.Popen(args, stdout=log_fps["trace"], stderr=subprocess.PIPE)
_, stderr = p.communicate()
printstderr,
Post a Comment for "Collecting Stderr In Memory With Subprocess.call"