From 349e80c95f8a918bd0af2bd886c7701d51ef6e3b Mon Sep 17 00:00:00 2001 From: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> Date: Fri, 19 Sep 2025 12:16:32 -0700 Subject: [PATCH] fix quoting for runInBackground --- src/features/execution/runInBackground.ts | 27 ++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/features/execution/runInBackground.ts b/src/features/execution/runInBackground.ts index 0543bc34..c9613250 100644 --- a/src/features/execution/runInBackground.ts +++ b/src/features/execution/runInBackground.ts @@ -12,11 +12,32 @@ export async function runInBackground( traceWarn('No Python executable found in environment; falling back to "python".'); executable = 'python'; } - // Check and quote the executable path if necessary - executable = quoteStringIfNecessary(executable); + + // Don't quote the executable path for spawn - it handles spaces correctly on its own + // Remove any existing quotes that might cause issues + // see https://github.com/nodejs/node/issues/7367 for more details on cp.spawn and quoting + if (executable.startsWith('"') && executable.endsWith('"')) { + executable = executable.substring(1, executable.length - 1); + } + const args = environment.execInfo?.activatedRun?.args ?? environment.execInfo?.run.args ?? []; const allArgs = [...args, ...options.args]; - traceInfo(`Running in background: ${executable} ${allArgs.join(' ')}`); + + // Log the command for debugging + traceInfo(`Running in background: "${executable}" ${allArgs.join(' ')}`); + + // Check if the file exists before trying to spawn it + try { + const fs = require('fs'); + if (!fs.existsSync(executable)) { + traceError( + `Python executable does not exist: ${executable}. Attempting to quote the path as a workaround...`, + ); + executable = quoteStringIfNecessary(executable); + } + } catch (err) { + traceWarn(`Error checking if executable exists: ${err instanceof Error ? err.message : String(err)}`); + } const proc = cp.spawn(executable, allArgs, { stdio: 'pipe', cwd: options.cwd, env: options.env });