subprocrunner
raw JSON → 2.0.1 verified Mon Apr 27 auth: no python
A wrapper library for Python's subprocess module that enhances readability and error handling. Current version 2.0.1 runs on Python >=3.7 with monthly/bimonthly releases.
pip install subprocrunner Common errors
error ModuleNotFoundError: No module named 'subprocrunner' ↓
cause Library not installed.
fix
Run
pip install subprocrunner. error AttributeError: 'NoneType' object has no attribute 'stdout' ↓
cause Trying to access stdout before running the command.
fix
Call
runner.run() before accessing runner.stdout. Warnings
breaking In version 2.0.0, the `run()` method no longer returns a tuple (returncode, stdout, stderr). It now returns a `SubprocessRunner` instance. Access output via attributes `returncode`, `stdout`, `stderr`. ↓
fix Update code from `returncode, stdout, stderr = runner.run()` to `runner.run(); returncode, stdout, stderr = runner.returncode, runner.stdout, runner.stderr`.
gotcha By default, `run()` raises `CalledProcessError` for non-zero exit codes. Set `raise_exception=False` to suppress this. ↓
fix Use `runner.run(raise_exception=False)` to handle errors manually.
Imports
- SubprocessRunner wrong
from subprocrunner import SubprocessRunner as SRcorrectfrom subprocrunner import SubprocessRunner
Quickstart
from subprocrunner import SubprocessRunner
runner = SubprocessRunner('echo Hello, world!')
runner.run()
print(runner.stdout)