Run a command and return stdout
(cmd: str)
| 114 | |
| 115 | |
| 116 | def run_command(cmd: str) -> str: |
| 117 | """Run a command and return stdout""" |
| 118 | try: |
| 119 | proc = RunningProcess(cmd, shell=True, auto_run=True, timeout=30) |
| 120 | from running_process import EndOfStream |
| 121 | |
| 122 | # `get_next_line` strips the trailing newline. Re-add it so callers |
| 123 | # that `output.split("\n")` actually get one entry per line rather |
| 124 | # than a single mega-line that no parser can split on whitespace |
| 125 | # (the cause of "nm: 1 symbols" on toolchains like xtensa-esp-elf |
| 126 | # whose nm prints many hundreds of lines). |
| 127 | output_lines: list[str] = [] |
| 128 | while line := proc.get_next_line(timeout=30): |
| 129 | if isinstance(line, EndOfStream): |
| 130 | break |
| 131 | output_lines.append(str(line)) |
| 132 | output = "\n".join(output_lines) |
| 133 | exit_code = proc.wait() |
| 134 | if exit_code != 0: |
| 135 | print(f"Error running command: {cmd}") |
| 136 | print(f"Exit code: {exit_code}") |
| 137 | return "" |
| 138 | return output |
| 139 | except KeyboardInterrupt as ki: |
| 140 | from ci.util.global_interrupt_handler import ( |
| 141 | handle_keyboard_interrupt, |
| 142 | ) |
| 143 | |
| 144 | handle_keyboard_interrupt(ki) |
| 145 | raise |
| 146 | except Exception as e: |
| 147 | print(f"Error running command: {cmd}") |
| 148 | print(f"Error: {e}") |
| 149 | return "" |
| 150 | |
| 151 | |
| 152 | def demangle_symbol(mangled_name: str, cppfilt_path: str) -> str: |
no test coverage detected