Skip to content

Instantly share code, notes, and snippets.

@4383
Created June 27, 2017 13:58
Show Gist options
  • Save 4383/f3e935f8b24417e1691f257566370b6e to your computer and use it in GitHub Desktop.
Save 4383/f3e935f8b24417e1691f257566370b6e to your computer and use it in GitHub Desktop.
python stdout handling like linux command tee
import subprocess, os, sys
# Unbuffer output
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
tee = subprocess.Popen(["tee", "log.txt"], stdin=subprocess.PIPE)
os.dup2(tee.stdin.fileno(), sys.stdout.fileno())
os.dup2(tee.stdin.fileno(), sys.stderr.fileno())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment