I have a problem forwarding the stdout of a subprocess to stdout of the current process.
This is my MWE caller code (runner.py):
import sys
import subprocess
import time
p = subprocess.Popen([sys.executable, "test.py"], stdout=sys.stdout)
time.sleep(10)
p.terminate()
and here is the content of the callee test.py:
import time
while True:
time.sleep(1)
print "Heartbeat"
The following will work and print all the heartbeats to the console:
python runner.py
However, the following does not work, the output text file remains empty (using Python 2.7):
python runner.py > test.txt
What do I have to do?