(cmd: list[str], cwd: Path, timeout: int | None = None)
| 132 | |
| 133 | |
| 134 | def run_cmd(cmd: list[str], cwd: Path, timeout: int | None = None) -> dict[str, Any]: |
| 135 | started = now_iso() |
| 136 | try: |
| 137 | result = subprocess.run( |
| 138 | cmd, |
| 139 | cwd=cwd, |
| 140 | check=False, |
| 141 | stdout=subprocess.PIPE, |
| 142 | stderr=subprocess.STDOUT, |
| 143 | text=True, |
| 144 | timeout=timeout, |
| 145 | env=_effective_env(), |
| 146 | ) |
| 147 | output = result.stdout or "" |
| 148 | return { |
| 149 | "cmd": cmd, |
| 150 | "cwd": str(cwd), |
| 151 | "started_at": started, |
| 152 | "finished_at": now_iso(), |
| 153 | "returncode": result.returncode, |
| 154 | "ok": result.returncode == 0, |
| 155 | "stdout_tail": output[-12000:], |
| 156 | } |
| 157 | except subprocess.TimeoutExpired as exc: |
| 158 | output = exc.stdout if isinstance(exc.stdout, str) else "" |
| 159 | return { |
| 160 | "cmd": cmd, |
| 161 | "cwd": str(cwd), |
| 162 | "started_at": started, |
| 163 | "finished_at": now_iso(), |
| 164 | "returncode": None, |
| 165 | "ok": False, |
| 166 | "error": f"TimeoutExpired: exceeded {timeout}s", |
| 167 | "stdout_tail": output[-12000:], |
| 168 | } |
| 169 | |
| 170 | |
| 171 | def run_cmd_stdout_to_file( |
no test coverage detected