I’m using the following to execute a process and hide its output from Python. It’s in a loop though, and I need a way to block until the sub process has terminated before moving to the next iteration.
subprocess.Popen(["scanx", "--udp", host], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Use
subprocess.call(). From the docs:Edit:
subprocess.call()useswait(), andwait()is vulnerable to deadlocks (as Tommy Herbert pointed out). From the docs:So if your command generates a lot of output, use
communicate()instead: