Skip to content

Instantly share code, notes, and snippets.

Created Jun 27, 2017
What would you like to do?
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