Python Forum
combining stdout and stderr - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: combining stdout and stderr (/thread-22147.html)



combining stdout and stderr - Skaperen - Nov-01-2019

i want to combine stdout and stderr on the same output so both can go over a single pipe. the buffering of stdout can mess up the line ordering. i don't want to solve that be eliminating buffering. i want output to either to be buffered in a common buffer. it seemed to work when i did
    import sys
    ...
    sys.stdout.flush() # not necessary if before any output
    sys.stderr.flush() # i have hit cases where it was buffered
    sys.stderr = sys.stdout
    ...
is there a more appropriate way to do this?


RE: combining stdout and stderr - Gribouillis - Nov-01-2019

Skaperen Wrote:is there a more appropriate way to do this?
I don't see one. The code looks very pythonic.