From 33040034780f2fd030d0925eb37619298b80d358 Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Tue, 30 Jul 2024 16:59:54 -0700 Subject: [PATCH] Spawn .bat/.cmd DebugAdapterExecutables with shell=true (#224350) Spawn .bat/.cmd DebugAdapterExecutables with shell=true (#224320) * Spawn .bat DAs with shell=true * Also escape args * And .cmd * escape argument properly * Don't escape \ --- .../workbench/contrib/debug/node/debugAdapter.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/debug/node/debugAdapter.ts b/src/vs/workbench/contrib/debug/node/debugAdapter.ts index 4275f9e0a89..43f92b4552f 100644 --- a/src/vs/workbench/contrib/debug/node/debugAdapter.ts +++ b/src/vs/workbench/contrib/debug/node/debugAdapter.ts @@ -222,13 +222,26 @@ export class ExecutableDebugAdapter extends StreamDebugAdapter { throw new Error(nls.localize('unableToLaunchDebugAdapterNoArgs', "Unable to launch debug adapter.")); } } else { + let spawnCommand = command; + let spawnArgs = args; const spawnOptions: cp.SpawnOptions = { env: env }; if (options.cwd) { spawnOptions.cwd = options.cwd; } - this.serverProcess = cp.spawn(command, args, spawnOptions); + if (platform.isWindows && (command.endsWith('.bat') || command.endsWith('.cmd'))) { + // https://github.com/microsoft/vscode/issues/224184 + spawnOptions.shell = true; + spawnCommand = `"${command}"`; + spawnArgs = args.map(a => { + a = a.replace(/"/g, '\\"'); // Escape existing double quotes with \ + // Wrap in double quotes + return `"${a}"`; + }); + } + + this.serverProcess = cp.spawn(spawnCommand, spawnArgs, spawnOptions); } this.serverProcess.on('error', err => {