Read console output of another program in Python
问题 There are two programs - parent.py and myscript.py, shown below. parent.py keeps printing messages in the console. And myscript.py needs access to what parent.py prints. parent.py: import time while 1: time.sleep(1) print "test" myscript.py: import subprocess p = None p = subprocess.Popen(['python', 'parent.py'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, ) for line in p.stdout: print line I want myscript.py to catch the output of parent.py dynamically. As it can be seen that parent.py