How do I handle input and output from a subprocess using `subprocess`?

Responsive Ad Header

Question

Grade: Education Subject: Support
How do I handle input and output from a subprocess using `subprocess`?
Asked by:
70 Viewed 70 Answers

Answer (70)

Best Answer
(335)
You can capture the output of a subprocess using the `stdout` and `stderr` attributes of the `subprocess` object. For example, `process.stdout` contains the standard output, and `process.stderr` contains the standard error. You can also redirect these streams using the `stdout=subprocess.PIPE` and `stderr=subprocess.PIPE` arguments.