subprocess.Popen()
subprocess.Popen() is a Python function in the Subprocess Module category. Executes a child program in a new process (lower-level than run()). The syntax is subprocess.Popen(args, bufsize=-1, executable=None, stdin=None, stdout=None, stderr=None, shell=False, cwd=None, env=None, text=None). Returns: Popen object. A typical example: p = subprocess.Popen(["ping", "google.com"], stdout=subprocess.PIPE)
output, _ = p.communicate()
print(output.decode()). A close sibling is subprocess.run(), which runs a command and waits for it to complete. Returns a CompletedProcess instance. A close sibling is Popen.communicate(), which sends data to stdin and reads from stdout/stderr until EOF. A close sibling is subprocess.call(), which runs a command and returns its return code (legacy API, use run() instead). A close sibling is subprocess.check_output(), which runs a command and returns its output as bytes. Raises CalledProcessError on failure. More about this category: Subprocess management — run, Popen, call, PIPE, CalledProcessError. For a broader walkthrough, read the Subprocess Module guide.