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)
| 29 | |
| 30 | |
| 31 | def run_command(command: List[str], return_stdout=False): |
| 32 | """ |
| 33 | Runs `command` with `subprocess.check_output` and will potentially return the `stdout`. Will also properly capture |
| 34 | if an error occurred while running `command` |
| 35 | """ |
| 36 | try: |
| 37 | output = subprocess.check_output(command, stderr=subprocess.STDOUT) |
| 38 | if return_stdout: |
| 39 | if hasattr(output, "decode"): |
| 40 | output = output.decode("utf-8") |
| 41 | return output |
| 42 | except subprocess.CalledProcessError as e: |
| 43 | raise SubprocessCallException( |
| 44 | f"Command `{' '.join(command)}` failed with the following error:\n\n{e.output.decode()}" |
| 45 | ) from e |
| 46 | |
| 47 | |
| 48 | class ExamplesTestsAccelerate(unittest.TestCase): |
no test coverage detected