EasyProcess
EasyProcess is a simple, easy-to-use Python subprocess interface, providing a convenient layer on top of the standard `subprocess` module. It simplifies starting and stopping programs, retrieving their standard output and error streams, and managing return codes. The library supports Python versions 3.7 through 3.12 and is currently at version 1.1.
Warnings
- gotcha EasyProcess does not support shell commands. Commands should be provided as a list of arguments. Passing a string will be split using `shlex.split`, but shell-specific commands (like `echo` on Windows) might not work as expected if they are not standalone executables.
- gotcha The `stdout` and `stderr` attributes of an `EasyProcess` object are only populated *after* the subprocess has finished execution (i.e., after `call()`, `wait()`, or `stop()` has completed and the process has terminated). Attempting to read them before the process ends will result in `None`.
- gotcha The `return_code` attribute is `None` until the managed subprocess has completed its execution and either `EasyProcess.stop()` or `EasyProcess.wait()` has been called.
- gotcha The `stop()` method only terminates the main process started by `EasyProcess` and does *not* automatically kill the entire subprocess tree (i.e., any child processes spawned by the main process). This can lead to orphaned processes.
Install
-
pip install EasyProcess
Imports
- EasyProcess
from easyprocess import EasyProcess
Quickstart
import sys
from easyprocess import EasyProcess
# Get the Python executable path
python_executable = sys.executable
# Run a simple Python command, wait for it, and get stdout
process_result = EasyProcess([python_executable, "-c", "print('Hello from EasyProcess')"]).call()
print("Stdout:", process_result.stdout)
print("Return Code:", process_result.return_code)