mirror of
https://github.com/shareAI-lab/analysis_claude_code.git
synced 2026-09-20 12:13:38 +08:00
fix: harden subprocess output decoding across lessons
This commit is contained in:
@@ -138,24 +138,14 @@ SYSTEM = build_system_prompt()
|
||||
|
||||
# -- Tools --
|
||||
|
||||
# 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:
|
||||
try:
|
||||
r = subprocess.run(command, shell=True, cwd=WORKDIR,
|
||||
capture_output=True, timeout=120)
|
||||
stdout = safe_decode(r.stdout)
|
||||
stderr = safe_decode(r.stderr)
|
||||
out = (stdout + stderr).strip()
|
||||
return out[:50000] if out else "(no output)"
|
||||
result = subprocess.run(
|
||||
command, shell=True, cwd=WORKDIR,
|
||||
capture_output=True, text=True, errors="replace", timeout=120,
|
||||
)
|
||||
output = (result.stdout + result.stderr).strip()
|
||||
return output[:50000] if output else "(no output)"
|
||||
except subprocess.TimeoutExpired:
|
||||
return "Error: Timeout (120s)"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user