What is Python's subprocess module?
Answer
The subprocess module runs external commands and system processes from Python. Modern API uses subprocess.run(): result = subprocess.run(["ls", "-la"], capture_output=True, text=True, timeout=30). Access output: result.stdout, result.stderr, result.returncode. Raise exception on failure: check=True raises CalledProcessError if returncode != 0. Pipe input: subprocess.run(["grep", "error"], input="log data", text=True). For long-running processes: use subprocess.Popen directly for streaming I/O. Security: never use shell=True with user-supplied input — leads to shell injection. Prefer list arguments (not strings). Environment variables: env={"PATH": "/usr/bin", **os.environ}. Alternatives: os.system() (deprecated, avoid), sh library (more ergonomic wrapper).