I'm in need of setting the stderr stream in a Popen call to line-buffered. I discovered the bufsize argument, but it applies to all of the stdin, stdout, and stderr files.
How do I adjust the buffering to be different for each file?
I assume you use PIPE for stderr? In that case, I think you can do something like this:
p = subprocess.Popen(..., stderr=subprocess.PIPE)
fd = p.stderr.fileno()
my_stderr = os.fdopen(os.dup(fd), 'rU', new_bufsize)
os.close(fd)
# use my_stderr from here on
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With