1
0
mirror of https://github.com/GuDaStudio/codexmcp.git synced 2026-02-12 02:47:43 +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,12 +36,12 @@ 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":
quoted_cmd = subprocess.list2cmdline(cmd)
popen_cmd = ["cmd", "/d", "/s", "/c", quoted_cmd]
else:
popen_cmd = cmd popen_cmd = cmd
codex_path = shutil.which('codex') or None # 替换运行路径
if codex_path is not None:
popen_cmd[0] = codex_path
process = subprocess.Popen( process = subprocess.Popen(
popen_cmd, popen_cmd,
shell=False, # Safer: no shell injection shell=False, # Safer: no shell injection
@@ -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()