Skip to content

Instantly share code, notes, and snippets.

@rsgalloway
Created August 1, 2014 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsgalloway/1e1d72b4f61cae119036 to your computer and use it in GitHub Desktop.
Save rsgalloway/1e1d72b4f61cae119036 to your computer and use it in GitHub Desktop.
redirect stdout
# 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