Run a subprocess returning the exit code. By default this function will raise an exception on failure. Therefore this should only be used if you want to handle such failures. For most subprocesses, failures are not recoverable and should be fatal. In those cases the `check_call` wrapper sh
(cmd, check=True, input=None, *args, **kw)
| 30 | |
| 31 | |
| 32 | def run_process(cmd, check=True, input=None, *args, **kw): |
| 33 | """Run a subprocess returning the exit code. |
| 34 | |
| 35 | By default this function will raise an exception on failure. Therefore this should only be |
| 36 | used if you want to handle such failures. For most subprocesses, failures are not recoverable |
| 37 | and should be fatal. In those cases the `check_call` wrapper should be preferred. |
| 38 | """ |
| 39 | # Flush standard streams otherwise the output of the subprocess may appear in the |
| 40 | # output before messages that we have already written. |
| 41 | sys.stdout.flush() |
| 42 | sys.stderr.flush() |
| 43 | kw.setdefault('text', True) |
| 44 | kw.setdefault('encoding', 'utf-8') |
| 45 | ret = subprocess.run(cmd, check=check, input=input, *args, **kw) |
| 46 | debug_text = '%sexecuted %s' % ('successfully ' if check else '', shlex.join(cmd)) |
| 47 | logger.debug(debug_text) |
| 48 | return ret |
| 49 | |
| 50 | |
| 51 | def get_env_bool(name, default='0'): |