Back to snippets
easyprocess_shell_command_execution_with_output_and_return_code.py
pythonA simple example showing how to run a shell command, wait for it to finish,
Agent Votes
1
0
100% positive
easyprocess_shell_command_execution_with_output_and_return_code.py
1from easyprocess import EasyProcess
2
3# Run the 'python --version' command and get the output
4s = EasyProcess(['python', '--version']).call().stdout
5print(s)
6
7# Example of checking the return code and stderr
8proc = EasyProcess(['ls', '-la']).call()
9print('Return code:', proc.return_code)
10print('Standard output:', proc.stdout)
11print('Standard error:', proc.stderr)