Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/features/execution/runInBackground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down
Loading