-
-
Notifications
You must be signed in to change notification settings - Fork 69.5k
[Bug]: Windows exec tool produces garbled Chinese characters due to hardcoded UTF-8 encoding #50519
Description
Bug type
Behavior bug (incorrect output/state without crash)
Summary
The runExec method in OpenClaw's exec tool hardcodes encoding: "utf8" when executing commands on Windows. This causes Chinese characters (and other non-ASCII characters) to become garbled (乱码) because Windows cmd.exe outputs in GBK/CP936 encoding by default, not UTF-8.
Steps to reproduce
- Use OpenClaw's exec tool on Windows
- Execute any command that outputs Chinese characters:
await exec("dir", ["D:\\测试文件夹"]); // or await exec("echo", ["你好世界"]);
- Observe garbled output
Expected behavior
Chinese characters should display correctly.
Actual behavior
Chinese characters appear as garbled text (e.g., ���IJ��� instead of 测试).
OpenClaw version
2026.3.13
Operating system
windows10
Install method
npm dev
Model
qwen-3.5
Provider / routing chain
openclaw
Additional provider/model setup details
No response
Logs, screenshots, and evidence
Impact and severity
No response
Additional information
Proposed Solutions
Option 1: Auto-detect Windows encoding (Recommended)
async function runExec(command, args, opts = 1e4) {
// Detect encoding based on platform
const defaultEncoding = process.platform === "win32" ? "gbk" : "utf8";
const options = typeof opts === "number" ? {
timeout: opts,
encoding: defaultEncoding
} : {
timeout: opts.timeoutMs,
maxBuffer: opts.maxBuffer,
cwd: opts.cwd,
encoding: opts.encoding ?? defaultEncoding // Allow override
};
// ...
}Option 2: Set UTF-8 code page before execution
async function runExec(command, args, opts = 1e4) {
// On Windows, prepend chcp 65001 to set UTF-8 code page
if (process.platform === "win32" && isWindowsBatchCommand(execCommand)) {
const cmdLine = `chcp 65001>nul && ${buildCmdExeCommandLine(execCommand, execArgs)}`;
// Execute with UTF-8 code page
}
// ...
}Option 3: Allow encoding configuration
async function runExec(command, args, opts = 1e4) {
const options = typeof opts === "number" ? {
timeout: opts,
encoding: "utf8"
} : {
timeout: opts.timeoutMs,
maxBuffer: opts.maxBuffer,
cwd: opts.cwd,
encoding: opts.encoding ?? "utf8" // Allow user to specify encoding
};
// ...
}Impact
This issue affects:
- All Windows users working with non-ASCII characters
- Chinese, Japanese, Korean, and other non-Latin script users
- File paths with non-ASCII characters
- Command output containing non-ASCII text
Workaround
Currently, users must:
- Avoid using exec tool for commands with Chinese characters
- Use alternative tools (list_files, read_file, etc.)
- Use PowerShell with JSON output:
powershell -Command "Get-ChildItem | ConvertTo-Json"
Additional Context
This is a common issue with Node.js child_process on Windows. The encoding option in execFile only affects how Node.js interprets the output buffer, but doesn't change the actual encoding used by cmd.exe.
Related Node.js documentation:
- https://nodejs.org/api/child_process.html#child_processexecfilefile-args-options-callback
- https://nodejs.org/api/buffer.html#buffers-and-character-encodings
References
- Similar issue in other projects: Node.js doesn't run as tty on windows / cygwin nodejs/node#3006
- Windows code page documentation: https://learn.microsoft.com/en-us/windows/win32/intl/code-page-identifiers