Use Python's stdlib `subprocess.run()` to shell out to system commands from your scripts ā capturing stdout and stderr, checking exit codes, raising errors on failure with `check=True`, and passing custom environments. Then extend `env_deploy_check.py` with a live system health check that shells out to `git` or `df`.
Create a dedicated directory, activate the virtual environment, and confirm the `subprocess` module is available. `subprocess` is part of the Python standard library ā no pip install needed.
mkdir -p ~/devops-python/lesson-203cd ~/devops-python/lesson-203source ~/devops-python/lesson-101/devops-env/bin/activatepython3 -c "import subprocess; print('subprocess module OK'); print('run available:', callable(subprocess.run))"The subprocess module lets Python scripts start external programs, capture their output, and react to their exit codes ā replacing the older os.system() and os.popen() calls. subprocess.run() is the high-level, recommended API added in Python 3.5.
It replaces subprocess.call(), subprocess.check_call(), and subprocess.check_output() for the vast majority of use cases.
Your terminal prompt shows (devops-env).
The one-liner prints subprocess module OK and run available: True.