Runs a command using `subprocess.run()`. Args: command: A string, the command to run. Multiple lines in `command` are treated as a single command. * If a line starts with `#` it is discarded. * If a line contains ` #`, the trailing
(
command,
*,
capture=False,
check=1,
verbose=1,
env=None,
env_extra=None,
timeout=None,
caller=1,
prefix=None,
encoding=None, # System default.
errors='backslashreplace',
)
| 2279 | |
| 2280 | |
| 2281 | def run( |
| 2282 | command, |
| 2283 | *, |
| 2284 | capture=False, |
| 2285 | check=1, |
| 2286 | verbose=1, |
| 2287 | env=None, |
| 2288 | env_extra=None, |
| 2289 | timeout=None, |
| 2290 | caller=1, |
| 2291 | prefix=None, |
| 2292 | encoding=None, # System default. |
| 2293 | errors='backslashreplace', |
| 2294 | ): |
| 2295 | ''' |
| 2296 | Runs a command using `subprocess.run()`. |
| 2297 | |
| 2298 | Args: |
| 2299 | command: |
| 2300 | A string, the command to run. |
| 2301 | |
| 2302 | Multiple lines in `command` are treated as a single command. |
| 2303 | |
| 2304 | * If a line starts with `#` it is discarded. |
| 2305 | * If a line contains ` #`, the trailing text is discarded. |
| 2306 | |
| 2307 | When running the command on Windows, newlines are replaced by |
| 2308 | spaces; otherwise each line is terminated by a backslash character. |
| 2309 | capture: |
| 2310 | If true, we include the command's output in our return value. |
| 2311 | check: |
| 2312 | If true we raise an exception on error; otherwise we include the |
| 2313 | command's returncode in our return value. |
| 2314 | verbose: |
| 2315 | If true we show the command. |
| 2316 | env: |
| 2317 | None or dict to use instead of <os.environ>. |
| 2318 | env_extra: |
| 2319 | None or dict to add to <os.environ> or <env>. |
| 2320 | timeout: |
| 2321 | If not None, timeout in seconds; passed directly to |
| 2322 | subprocess.run(). Note that on MacOS subprocess.run() seems to |
| 2323 | leave processes running if timeout expires. |
| 2324 | prefix: |
| 2325 | String prefix for each line of output. |
| 2326 | |
| 2327 | If true: |
| 2328 | * We run command with stdout=subprocess.PIPE and |
| 2329 | stderr=subprocess.STDOUT, repetaedly reading the command's output |
| 2330 | and writing it to stdout with <prefix>. |
| 2331 | * We do not support <timeout>, which must be None. |
| 2332 | Returns: |
| 2333 | check capture Return |
| 2334 | -------------------------- |
| 2335 | false false returncode |
| 2336 | false true (returncode, output) |
| 2337 | true false None or raise exception |
| 2338 | true true output or raise exception |
no test coverage detected