elias bothell elias bothell - 9 months ago 56
Python Question

How do I hide the output from a subprocess and continue the script execution?

How do I start a subprocess or run a python file that has a continuous stream of output and simultaneously run the rest of the script?

here is some example code:

import subprocess

p = subprocess.Popen('python myScript.py', shell=True, stdout=subprocess.PIPE)

#this program will have a stream of output and is designed to run for
#long periods of time

print 'the program is still running!'


Answer Source

After calling subprocess.Popen() in your sample code, the main process will immediately comes to the print() statement and then execute doMoreStuff(), running the rest of script simultaneously.