Created
August 1, 2014 21:06
-
-
Save rsgalloway/1e1d72b4f61cae119036 to your computer and use it in GitHub Desktop.
redirect stdout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# open our log file | |
so = se = open("stdout.log", 'a', 0) | |
# re-open stdout without buffering | |
sys.stdout = os.fdopen(sys.stdout.fileno(), 'a', 0) | |
# redirect stdout and stderr to the log file opened above | |
os.dup2(so.fileno(), sys.stdout.fileno()) | |
os.dup2(se.fileno(), sys.stderr.fileno()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment