RosettaCodeData/Task/Execute-a-system-command/Python/execute-a-system-command-2.py
2023-07-01 13:44:08 -04:00

5 lines
242 B
Python

import subprocess
# if the exit code was non-zero these commands raise a CalledProcessError
exit_code = subprocess.check_call(['ls', '-l']) # Python 2.5+
assert exit_code == 0
output = subprocess.check_output(['ls', '-l']) # Python 2.7+