def run_command()

in pkgs/rewrite-nix-paths-macho/rewrite-nix-paths-macho.py [0:0]


def run_command(command: List[str], check: bool = True) -> str:
    """Executes a shell command and returns its output."""
    try:
        result = subprocess.run(
            command, check=check, capture_output=True, text=True, encoding="utf-8"
        )
        return result.stdout.strip()
    except FileNotFoundError:
        print(
            f"Error: Command '{command[0]}' not found. Is it in your PATH?",
            file=sys.stderr,
        )
        sys.exit(1)
    except subprocess.CalledProcessError as e:
        print(f"Error executing command: {' '.join(command)}", file=sys.stderr)
        print(f"Output:\n{e.stderr}", file=sys.stderr)
        sys.exit(1)