forked from farhoodlabs/paperclip
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user