Runs `command` with `subprocess.check_output` and will potentially return the `stdout`. Will also properly capture if an error occured while running `command`
(command: List[str], return_stdout=False)
| 2143 | |
| 2144 | |
| 2145 | def run_command(command: List[str], return_stdout=False): |
| 2146 | """ |
| 2147 | Runs `command` with `subprocess.check_output` and will potentially return the `stdout`. Will also properly capture |
| 2148 | if an error occured while running `command` |
| 2149 | """ |
| 2150 | try: |
| 2151 | output = subprocess.check_output(command, stderr=subprocess.STDOUT) |
| 2152 | if return_stdout: |
| 2153 | if hasattr(output, "decode"): |
| 2154 | output = output.decode("utf-8") |
| 2155 | return output |
| 2156 | except subprocess.CalledProcessError as e: |
| 2157 | raise SubprocessCallException( |
| 2158 | f"Command `{' '.join(command)}` failed with the following error:\n\n{e.output.decode()}" |
| 2159 | ) from e |
| 2160 | |
| 2161 | |
| 2162 | class RequestCounter: |
no test coverage detected