1
0
mirror of https://github.com/GuDaStudio/codexmcp.git synced 2026-02-10 02:34:32 +08:00

v0.4.2:修复Windows下编码bug

This commit is contained in:
GuDaStudio
2025-11-10 12:45:01 +08:00
parent 5b1a839d63
commit ab8d342596

View File

@@ -13,6 +13,7 @@ from typing import Annotated, Any, Dict, Generator, Literal, Optional
from mcp.server.fastmcp import FastMCP from mcp.server.fastmcp import FastMCP
from pydantic import BeforeValidator, Field from pydantic import BeforeValidator, Field
import shutil
mcp = FastMCP("Codex MCP Server-from guda.studio") mcp = FastMCP("Codex MCP Server-from guda.studio")
@@ -35,11 +36,11 @@ def run_shell_command(cmd: list[str]) -> Generator[str, None, None]:
""" """
# On Windows, codex is exposed via a *.cmd shim. Use cmd.exe with /s so # On Windows, codex is exposed via a *.cmd shim. Use cmd.exe with /s so
# user prompts containing quotes/newlines aren't reinterpreted as shell syntax. # user prompts containing quotes/newlines aren't reinterpreted as shell syntax.
if os.name == "nt": popen_cmd = cmd
quoted_cmd = subprocess.list2cmdline(cmd)
popen_cmd = ["cmd", "/d", "/s", "/c", quoted_cmd] codex_path = shutil.which('codex') or None # 替换运行路径
else: if codex_path is not None:
popen_cmd = cmd popen_cmd[0] = codex_path
process = subprocess.Popen( process = subprocess.Popen(
popen_cmd, popen_cmd,
@@ -48,7 +49,7 @@ def run_shell_command(cmd: list[str]) -> Generator[str, None, None]:
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
universal_newlines=True, universal_newlines=True,
bufsize=1, encoding='utf-8',
) )
output_queue: queue.Queue[str] = queue.Queue() output_queue: queue.Queue[str] = queue.Queue()