subprocess usage - ryanm292002/CAPSTONE GitHub Wiki
Usage
To use the subprocess module, you must import it into your Python script:
import subprocess
Examples
Here are some common uses of the subprocess module:
Running an External Command The following runs a basic echo which prints out "Hello World" in result section:
subprocess.run(['echo', 'Hello, World!'])
Capturing Command Output
To capture the output of a command, use the capture_output=True argument:
result = subprocess.run(['ls', '-l'], capture_output=True, text=True) print(result.stdout)
Handling Errors
To handle errors in a subprocess, check the returncode:
result = subprocess.run(['false']) # 'false's if result.returncode != 0: print("Error: Command failed with status", result.returncode)