subprocess.check_output()
subprocess.check_output() is a Python function in the Subprocess Module category. Runs a command and returns its output as bytes. Raises CalledProcessError on failure. The syntax is subprocess.check_output(args, *, stdin=None, stderr=subprocess.STDOUT, shell=False, cwd=None, timeout=None). Returns: Bytes output. A typical example: output = subprocess.check_output(["echo", "hello"])
print(output) # b"hello\n". A close sibling is subprocess.run(), which runs a command and waits for it to complete. Returns a CompletedProcess instance. A close sibling is subprocess.Popen(), which executes a child program in a new process (lower-level than run()). 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). More about this category: Subprocess management — run, Popen, call, PIPE, CalledProcessError. For a broader walkthrough, read the Subprocess Module guide. Related Subprocess Module entries: subprocess.run(), subprocess.Popen(), Popen.communicate(), subprocess.call(), subprocess.check_call(), subprocess.PIPE.