Run a command using subprocess and capture the output. Args: command (list or str): Command to run. show_output (bool): Print command and its output if True. Returns: str: Standard output of the command. Raises: RuntimeError: If the command fails.
(command: list[str] | str, show_output: bool = False)
| 11 | |
| 12 | |
| 13 | def _run_command(command: list[str] | str, show_output: bool = False) -> str: |
| 14 | """ |
| 15 | Run a command using subprocess and capture the output. |
| 16 | |
| 17 | Args: |
| 18 | command (list or str): Command to run. |
| 19 | show_output (bool): Print command and its output if True. |
| 20 | |
| 21 | Returns: |
| 22 | str: Standard output of the command. |
| 23 | |
| 24 | Raises: |
| 25 | RuntimeError: If the command fails. |
| 26 | """ |
| 27 | if isinstance(command, str): |
| 28 | command = [command] |
| 29 | |
| 30 | if show_output: |
| 31 | print(f"Running command: {' '.join(command)}") |
| 32 | |
| 33 | result = subprocess.run(command, capture_output=True, text=True) |
| 34 | if result.returncode != 0: |
| 35 | if show_output: |
| 36 | print(f"Command failed: {' '.join(command)}") |
| 37 | print(f"Error: {result.stderr}") |
| 38 | raise RuntimeError(f"Command failed: {' '.join(command)}\n{result.stderr}") |
| 39 | |
| 40 | if show_output and result.stdout: |
| 41 | print(f"Command output: {result.stdout}") |
| 42 | return result.stdout |
| 43 | |
| 44 | |
| 45 | def _detect_platform_from_paths(as_path: Path, ld_path: Path): |
no test coverage detected