mirror of
https://github.com/shareAI-lab/analysis_claude_code.git
synced 2026-09-20 12:13:38 +08:00
fix(s07): resolve Windows subprocess UnicodeDecodeError with UTF-8/GBK fallback
This commit is contained in:
@@ -119,11 +119,23 @@ def safe_path(p: str) -> Path:
|
|||||||
raise ValueError(f"Path escapes workspace: {p}")
|
raise ValueError(f"Path escapes workspace: {p}")
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
# s07: Fix Windows subprocess encoding crash (fallback UTF-8 -> GBK with error replacement)
|
||||||
|
def safe_decode(data: bytes) -> str:
|
||||||
|
if not data:
|
||||||
|
return ""
|
||||||
|
try:
|
||||||
|
return data.decode('utf-8')
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
return data.decode('gbk')
|
||||||
|
|
||||||
|
|
||||||
def run_bash(command: str) -> str:
|
def run_bash(command: str) -> str:
|
||||||
try:
|
try:
|
||||||
r = subprocess.run(command, shell=True, cwd=WORKDIR,
|
r = subprocess.run(command, shell=True, cwd=WORKDIR,
|
||||||
capture_output=True, text=True, timeout=120)
|
capture_output=True, timeout=120)
|
||||||
out = (r.stdout + r.stderr).strip()
|
stdout = safe_decode(r.stdout)
|
||||||
|
stderr = safe_decode(r.stderr)
|
||||||
|
out = (stdout + stderr).strip()
|
||||||
return out[:50000] if out else "(no output)"
|
return out[:50000] if out else "(no output)"
|
||||||
except subprocess.TimeoutExpired:
|
except subprocess.TimeoutExpired:
|
||||||
return "Error: Timeout (120s)"
|
return "Error: Timeout (120s)"
|
||||||
|
|||||||
Reference in New Issue
Block a user