Python Programming - Standard Libraries - Discussion

Discussion Forum : Standard Libraries - General Questions (Q.No. 78)
78.
How can you use the subprocess module in Python to run an external command and capture its output?
subprocess.run(command, capture_output=True)
subprocess.execute(command, capture=True)
subprocess.call(command, capture=True)
subprocess.execute(command, capture_output=True)
Answer: Option
Explanation:
import subprocess

# Example usage of subprocess module for running an external command and capturing its output
result = subprocess.run(['ls', '-l'], capture_output=True, text=True)
print(result.stdout)
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.