Skip to content

Commit ad6ee20

Browse files
24kchengYeclaude
andcommitted
fix: Chinese path encoding on Windows (chcp 65001 UTF-8 codepage)
- Prefix all cmd.exe commands with chcp 65001 for UTF-8 encoding - Fixes garbled Chinese characters in file paths and git output - Applied to both sync and async command execution paths Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9a2fc09 commit ad6ee20

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

main/src/utils/commandExecutor.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class CommandExecutor {
8585
const enhancedOptions = {
8686
...cleanOptions,
8787
maxBuffer: cleanOptions?.maxBuffer || 10 * 1024 * 1024,
88+
encoding: (cleanOptions?.encoding || 'utf-8') as BufferEncoding,
8889
env: {
8990
...process.env,
9091
...cleanOptions?.env,
@@ -96,8 +97,13 @@ class CommandExecutor {
9697
}
9798
};
9899

100+
// On Windows, prefix command with chcp 65001 to set UTF-8 codepage
101+
const effectiveCommand = process.platform === 'win32'
102+
? `chcp 65001 >nul 2>&1 && ${command}`
103+
: command;
104+
99105
try {
100-
const result = nodeExecSync(command, enhancedOptions as ExecSyncOptions);
106+
const result = nodeExecSync(effectiveCommand, enhancedOptions as ExecSyncOptions);
101107

102108
// Log success with a preview of the result (unless silent mode)
103109
if (result && !silentMode) {
@@ -189,8 +195,13 @@ class CommandExecutor {
189195
}
190196
};
191197

198+
// On Windows, prefix command with chcp 65001 to set UTF-8 codepage
199+
const effectiveAsyncCommand = process.platform === 'win32'
200+
? `chcp 65001 >nul 2>&1 && ${command}`
201+
: command;
202+
192203
try {
193-
const result = await nodeExecAsync(command, enhancedOptions);
204+
const result = await nodeExecAsync(effectiveAsyncCommand, enhancedOptions);
194205

195206
if (result.stdout) {
196207
const stdout = String(result.stdout);

0 commit comments

Comments
 (0)