Skip to content

Instantly share code, notes, and snippets.

@4383
Created Jun 27, 2017
Embed
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