The `executor` package is a simple wrapper for Python's `subprocess` module, designed to simplify handling external commands on UNIX systems. It provides an object-oriented interface with proper argument escaping and error checking. Features include support for local commands, remote commands over SSH, execution within chroots, and concurrent command execution through command pools. The library's latest version is 23.2, released in November 2020, with an irregular release cadence.
pip install executorVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to run basic commands, handle their success/failure, provide standard input, and capture standard output using the `execute` function.
For complex or asynchronous command execution, migrate from direct `execute()` calls to using `ExternalCommand` instances, calling `start()` and `wait()` as needed. Simple synchronous calls to `execute()` remain compatible.
Verify functionality on target non-UNIX platforms or consider alternative libraries if cross-platform compatibility is critical for all features. For basic subprocess execution, it might work, but advanced features are UNIX-specific.
If a non-zero exit code is expected and should not raise an exception, pass `check=False` to the `execute()` function (e.g., `execute('false', check=False)`). The function will then return `False` for failure and `True` for success.For asynchronous execution, instantiate `ExternalCommand` (e.g., `cmd = ExternalCommand(['long_running_script'])`), call `cmd.start()`, and later `cmd.wait()` to retrieve results, or poll its status.
Review code that relies on implicit `command` requirement or attempts to modify the `command` property directly. While this change generally improves flexibility, older code might rely on the prior, stricter behavior or expect `command` to be immutable after initialization.
Catch the `ExternalCommandFailed` exception to handle command failures gracefully. You can access the command's output or error streams from the exception object to diagnose the issue. Alternatively, set `check=False` when calling `execute()` if you don't want non-zero exit codes to raise an exception, though this is generally not recommended for robust error handling.
Verify the correct spelling of the command and ensure it is installed and available in the system's PATH. For remote commands, ensure the command exists on the remote host. You can also specify the full path to the executable to bypass PATH lookups.
Install the `executor` package using pip: `pip install executor`. Ensure that you are running your script in the Python environment where the package was installed.
Handle the `RemoteCommandFailed` exception. Inspect the output from the remote command (usually available through the exception object) to understand why it failed. Ensure the command works correctly when executed directly on the remote host via SSH.
No dependency data recorded yet.