Runs `command` with `subprocess.check_output` and will potentially return the `stdout`. Will also properly capture if an error occurred while running `command`
(command: List[str], return_stdout=False)
| 17 | |
| 18 | # Taken from `test_examples_utils.py` |
| 19 | def run_command(command: List[str], return_stdout=False): |
| 20 | """ |
| 21 | Runs `command` with `subprocess.check_output` and will potentially return the `stdout`. Will also properly capture |
| 22 | if an error occurred while running `command` |
| 23 | """ |
| 24 | try: |
| 25 | output = subprocess.check_output(command, stderr=subprocess.STDOUT) |
| 26 | if return_stdout: |
| 27 | if hasattr(output, "decode"): |
| 28 | output = output.decode("utf-8") |
| 29 | return output |
| 30 | except subprocess.CalledProcessError as e: |
| 31 | raise SubprocessCallException( |
| 32 | f"Command `{' '.join(command)}` failed with the following error:\n\n{e.output.decode()}" |
| 33 | ) from e |
| 34 | |
| 35 | |
| 36 | def main(): |
no test coverage detected