Created
June 27, 2017 13:58
-
-
Save 4383/f3e935f8b24417e1691f257566370b6e to your computer and use it in GitHub Desktop.
python stdout handling like linux command tee
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
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