Run the script with the given params. :param list params: List of parameters to pass to subprocess.run :param callable log: Logger method to use for errors
(params: list[str], log: Callable[[str], None]=logger.error)
| 174 | |
| 175 | |
| 176 | def run_script(params: list[str], log: Callable[[str], None]=logger.error) -> tuple[str, str]: |
| 177 | """Run the script with the given params. |
| 178 | |
| 179 | :param list params: List of parameters to pass to subprocess.run |
| 180 | :param callable log: Logger method to use for errors |
| 181 | |
| 182 | """ |
| 183 | try: |
| 184 | proc = subprocess.run(params, |
| 185 | check=False, |
| 186 | stdout=subprocess.PIPE, |
| 187 | stderr=subprocess.PIPE, |
| 188 | universal_newlines=True, |
| 189 | env=env_no_snap_for_external_calls()) |
| 190 | |
| 191 | except (OSError, ValueError): |
| 192 | msg = "Unable to run the command: %s" % " ".join(params) |
| 193 | log(msg) |
| 194 | raise errors.SubprocessError(msg) |
| 195 | |
| 196 | if proc.returncode != 0: |
| 197 | msg = "Error while running %s.\n%s\n%s" % ( |
| 198 | " ".join(params), proc.stdout, proc.stderr) |
| 199 | # Enter recovery routine... |
| 200 | log(msg) |
| 201 | raise errors.SubprocessError(msg) |
| 202 | |
| 203 | return proc.stdout, proc.stderr |
| 204 | |
| 205 | |
| 206 | def exe_exists(exe: str) -> bool: |