mirror of
https://github.com/GuDaStudio/codexmcp.git
synced 2026-02-05 02:00:24 +08:00
v0.4.2:修复Windows下编码bug
This commit is contained in:
@@ -13,6 +13,7 @@ from typing import Annotated, Any, Dict, Generator, Literal, Optional
|
||||
|
||||
from mcp.server.fastmcp import FastMCP
|
||||
from pydantic import BeforeValidator, Field
|
||||
import shutil
|
||||
|
||||
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
|
||||
# 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
|
||||
|
||||
codex_path = shutil.which('codex') or None # 替换运行路径
|
||||
if codex_path is not None:
|
||||
popen_cmd[0] = codex_path
|
||||
|
||||
process = subprocess.Popen(
|
||||
popen_cmd,
|
||||
shell=False, # Safer: no shell injection
|
||||
@@ -48,7 +49,7 @@ def run_shell_command(cmd: list[str]) -> Generator[str, None, None]:
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True,
|
||||
bufsize=1,
|
||||
encoding='utf-8',
|
||||
)
|
||||
|
||||
output_queue: queue.Queue[str] = queue.Queue()
|
||||
|
||||
Reference in New Issue
Block a user