What is Python's subprocess module?
Why Interviewers Ask This
Candidates at the intermediate level are expected to not only know this concept but explain the trade-offs involved. Interviewers use this question to see if you can reason about design decisions, not just recall facts.
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).
Pro Tip
This topic has Python-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.