Python Forum

Full Version: can i merge stderr and stdout?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
can i merge stderr and stdout? is this a way to do it?
sys.stderr.flush()
sys.stdout.flush()
sys.stderr=sys.stdout
i also want to have them buffered together so there is no chance of their output being in different order. but the primary goal is to get all output to stdout (or to stderr in other cases).

when i do shell redirection to a common descriptor, output order can be mixed in the wrong order due to stdout buffering delaying output.
I think:
import sys

sys.stdout = open('filename', 'w')
sys.stderr = sys.stdout
You'll have to try it.
it writes to the file, so it might work that way.