fix: force UTF-8 output for PowerShell code_run

This commit is contained in:
Jiaqing Liang committed 2026-05-26 12:16:30 +08:00
1 parent e308f1d876
commit ae03ceba40
1 file changed
+2 -1
+2 -1
View File
@@ -28,7 +28,8 @@ def code_run(code, code_type="python", timeout=60, cwd=None, code_cwd=None, stop
elif code_type in ["powershell", "bash", "sh", "shell", "ps1", "pwsh"]:
if os.name == 'nt':
_ps = "pwsh" if shutil.which("pwsh") else "powershell"
cmd = [_ps, "-NoProfile", "-NonInteractive", "-Command", code]
utf8_prefix = "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; "
cmd = [_ps, "-NoProfile", "-NonInteractive", "-Command", utf8_prefix + code]
else: cmd = ["bash", "-c", code]
else:
return {"status": "error", "msg": f"不支持的类型: {code_type}"}