Skip to content

Commit 13652a1

Browse files
author
Yaohua-Leo
committed
fix(exec): default to GBK encoding on Windows (#50519)
- On Windows, cmd.exe outputs in GBK/CP936 by default, not UTF-8 - Changed default encoding from UTF-8 to GBK for Windows platform - Added encoding option to allow override when needed - This fixes garbled Chinese characters in exec tool output on Windows Fixes #50519
1 parent 003ca01 commit 13652a1

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/process/exec.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,21 @@ export function shouldSpawnWithShell(params: {
100100
export async function runExec(
101101
command: string,
102102
args: string[],
103-
opts: number | { timeoutMs?: number; maxBuffer?: number; cwd?: string } = 10_000,
103+
opts:
104+
| number
105+
| { timeoutMs?: number; maxBuffer?: number; cwd?: string; encoding?: BufferEncoding } = 10_000,
104106
): Promise<{ stdout: string; stderr: string }> {
107+
// On Windows, default to gbk encoding for cmd.exe output (CP936),
108+
// otherwise use utf8. Allow override via opts.encoding.
109+
const defaultEncoding: BufferEncoding = process.platform === "win32" ? "gbk" : "utf8";
105110
const options =
106111
typeof opts === "number"
107-
? { timeout: opts, encoding: "utf8" as const }
112+
? { timeout: opts, encoding: defaultEncoding }
108113
: {
109114
timeout: opts.timeoutMs,
110115
maxBuffer: opts.maxBuffer,
111116
cwd: opts.cwd,
112-
encoding: "utf8" as const,
117+
encoding: opts.encoding ?? defaultEncoding,
113118
};
114119
try {
115120
const argv = [command, ...args];

0 commit comments

Comments
 (0)