OCDocker.Toolbox.Running module¶
Sets of classes and functions that are used to run commands in the OS.
Usage:
import OCDocker.Toolbox.Running as ocrun
- exception OCDocker.Toolbox.Running.SubprocessError(message, cmd, cwd, returncode, stderr, stdout_log, report_path)[source]¶
Bases:
RuntimeErrorException raised when a subprocess fails and OCDOCKER_RAISE_SUBPROCESS is enabled.
- Parameters:
message (str) – Summary of the failure.
cmd (List[str]) – Command that was executed.
cwd (str) – Working directory used for the command.
returncode (int) – Exit code from the subprocess.
stderr (str) – Captured stderr output.
stdout_log (str) – Path to the stdout log file.
report_path (str) – Path to the failure report file.
- Return type:
None
- OCDocker.Toolbox.Running.is_tool_available(exe)[source]¶
Check if a tool executable is available.
- Parameters:
exe (str) – Path to the executable (can be absolute or command name)
- Returns:
True if the executable is available, False otherwise
- Return type:
bool
- OCDocker.Toolbox.Running.run(cmd, logFile='', cwd='', timeout=None)[source]¶
Run the given command (generic).
- Parameters:
cmd (List[str]) – The command to be run.
logFile (str, optional) – The file where the output will be saved. Default is “”.
cwd (str, optional) – The current working directory. Default is “”.
Environment –
----------- –
OCDOCKER_SUBPROCESS_TAIL_LINES (int) – Number of lines to include from stderr/stdout tail (default: 20).
OCDOCKER_DEBUG_SUBPROCESS (bool) – If enabled, include stdout tail and environment snapshot in the failure report.
OCDOCKER_RAISE_SUBPROCESS (bool) – If enabled, raise SubprocessError on failure instead of returning an error code.
timeout (int | None) –
- Returns:
The exit code of the command (based on the Error.py code table) or a tuple with the exit code and the stderr of the command.
- Return type:
int | Tuple[int, str]