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:
@@ -70,7 +70,7 @@ def execute_tool(name: str, args: dict) -> str:
|
||||
try:
|
||||
r = subprocess.run(
|
||||
args["command"], shell=True, cwd=WORKDIR,
|
||||
capture_output=True, text=True, timeout=60
|
||||
capture_output=True, text=True, errors="replace", timeout=60
|
||||
)
|
||||
return (r.stdout + r.stderr).strip() or "(empty)"
|
||||
except subprocess.TimeoutExpired:
|
||||
|
||||
@@ -168,7 +168,7 @@ def run_bash(command: str) -> str:
|
||||
shell=True,
|
||||
cwd=WORKDIR,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
text=True, errors="replace",
|
||||
timeout=60
|
||||
)
|
||||
output = (result.stdout + result.stderr).strip()
|
||||
|
||||
@@ -63,7 +63,7 @@ def run(prompt, history=[]):
|
||||
if b.type == "tool_use":
|
||||
print(f"> {{b.input['command']}}")
|
||||
try:
|
||||
out = subprocess.run(b.input["command"], shell=True, capture_output=True, text=True, timeout=60)
|
||||
out = subprocess.run(b.input["command"], shell=True, capture_output=True, text=True, errors="replace", timeout=60)
|
||||
output = (out.stdout + out.stderr).strip() or "(empty)"
|
||||
except Exception as e:
|
||||
output = f"Error: {{e}}"
|
||||
@@ -133,7 +133,7 @@ def execute(name: str, args: dict) -> str:
|
||||
if any(d in args["command"] for d in dangerous):
|
||||
return "Error: Dangerous command blocked"
|
||||
try:
|
||||
r = subprocess.run(args["command"], shell=True, cwd=WORKDIR, capture_output=True, text=True, timeout=60)
|
||||
r = subprocess.run(args["command"], shell=True, cwd=WORKDIR, capture_output=True, text=True, errors="replace", timeout=60)
|
||||
return (r.stdout + r.stderr).strip()[:50000] or "(empty)"
|
||||
except subprocess.TimeoutExpired:
|
||||
return "Error: Timeout (60s)"
|
||||
|
||||
Reference in New Issue
Block a user