Merge pull request #2397 from HearthCore/fix/win11-opencode-cmd-shell

fix: use real cmd.exe for Windows .cmd/.bat adapter invocation
This commit is contained in:
Dotta 2026-04-07 16:56:36 -05:00 committed by GitHub
commit 6e894f27a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -474,6 +474,11 @@ function quoteForCmd(arg: string) {
return /[\s"&<>|^()]/.test(escaped) ? `"${escaped}"` : escaped;
}
function resolveWindowsCmdShell(env: NodeJS.ProcessEnv): string {
const fallbackRoot = env.SystemRoot || process.env.SystemRoot || "C:\\Windows";
return path.join(fallbackRoot, "System32", "cmd.exe");
}
async function resolveSpawnTarget(
command: string,
args: string[],
@ -488,7 +493,9 @@ async function resolveSpawnTarget(
}
if (/\.(cmd|bat)$/i.test(executable)) {
const shell = env.ComSpec || process.env.ComSpec || "cmd.exe";
// Always use cmd.exe for .cmd/.bat wrappers. Some environments override
// ComSpec to PowerShell, which breaks cmd-specific flags like /d /s /c.
const shell = resolveWindowsCmdShell(env);
const commandLine = [quoteForCmd(executable), ...args.map(quoteForCmd)].join(" ");
return {
command: shell,