Execution
provide.foundation.process.sync.execution
¶
TODO: Add module docstring.
Classes¶
Functions¶
run
¶
run(
cmd: list[str] | str,
cwd: str | Path | None = None,
env: Mapping[str, str] | None = None,
capture_output: bool = True,
check: bool = True,
timeout: float | None = None,
text: bool = True,
input: str | bytes | None = None,
shell: bool = False,
**kwargs: Any
) -> CompletedProcess
Run a subprocess command with consistent error handling and logging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
list[str] | str
|
Command and arguments as a list |
required |
cwd
|
str | Path | None
|
Working directory for the command |
None
|
env
|
Mapping[str, str] | None
|
Environment variables (if None, uses current environment) |
None
|
capture_output
|
bool
|
Whether to capture stdout/stderr |
True
|
check
|
bool
|
Whether to raise exception on non-zero exit |
True
|
timeout
|
float | None
|
Command timeout in seconds |
None
|
text
|
bool
|
Whether to decode output as text |
True
|
input
|
str | bytes | None
|
Input to send to the process |
None
|
shell
|
bool
|
Whether to run command through shell |
False
|
**kwargs
|
Any
|
Additional arguments passed to subprocess.run |
{}
|
Returns:
| Type | Description |
|---|---|
CompletedProcess
|
CompletedProcess with results |
Raises:
| Type | Description |
|---|---|
ProcessError
|
If command fails and check=True |
ProcessTimeoutError
|
If timeout is exceeded |
Source code in provide/foundation/process/sync/execution.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
run_simple
¶
Simple wrapper for run that returns stdout as a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
list[str]
|
Command and arguments as a list |
required |
cwd
|
str | Path | None
|
Working directory for the command |
None
|
**kwargs
|
Any
|
Additional arguments passed to run |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
Stdout as a stripped string |
Raises:
| Type | Description |
|---|---|
ProcessError
|
If command fails |