toolr.utils.command¶
Public interface to the rust command extension module.
It provides a simple interface to run commands and stream/capture their output.
run ¶
run(
args: Sequence[str],
*,
cwd: str | Path | None = None,
env: ENVIRON = None,
input: str | bytes | None = None,
stream_output: bool = False,
capture_output: bool = False,
text: bool = True,
encoding: str | None = "utf-8",
timeout_secs: float | None = None,
no_output_timeout_secs: float | None = None,
) -> CommandResult[str] | CommandResult[bytes]
Run a command in a subprocess.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args
|
Sequence[str]
|
Command and arguments to run |
required |
cwd
|
str | Path | None
|
Current working directory to run the command in. Defaults to the current directory. |
None
|
env
|
ENVIRON
|
Environment variables to pass to the command |
None
|
input
|
str | bytes | None
|
Input data to pass to the command |
None
|
stream_output
|
bool
|
Whether to stream output to stdout/stderr |
False
|
capture_output
|
bool
|
Whether to capture output to return |
False
|
text
|
bool
|
Whether to return output as text or bytes |
True
|
encoding
|
str | None
|
Encoding to use for text output |
'utf-8'
|
timeout_secs
|
float | None
|
Maximum time to wait for command completion |
None
|
no_output_timeout_secs
|
float | None
|
Maximum time to wait without output |
None
|
Returns:
Type | Description |
---|---|
CommandResult[str] | CommandResult[bytes]
|
CommandResult object containing stdout, stderr, and return code |
Raises:
Type | Description |
---|---|
CommandError
|
If any of the pre-run checks fail or an operational failure happens. |
CommandTimeoutError
|
If the command times out |
CommandTimeoutNoOutputError
|
If the command produces no output for too long |
Source code in python/toolr/utils/command.py
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 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|