Skip to content

Commit 0d1ee29

Browse files
authored
fix quoting for runInBackground (#849)
fixes microsoft/vscode-python#25448
1 parent e8d2670 commit 0d1ee29

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/features/execution/runInBackground.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,32 @@ export async function runInBackground(
1212
traceWarn('No Python executable found in environment; falling back to "python".');
1313
executable = 'python';
1414
}
15-
// Check and quote the executable path if necessary
16-
executable = quoteStringIfNecessary(executable);
15+
16+
// Don't quote the executable path for spawn - it handles spaces correctly on its own
17+
// Remove any existing quotes that might cause issues
18+
// see https://github.com/nodejs/node/issues/7367 for more details on cp.spawn and quoting
19+
if (executable.startsWith('"') && executable.endsWith('"')) {
20+
executable = executable.substring(1, executable.length - 1);
21+
}
22+
1723
const args = environment.execInfo?.activatedRun?.args ?? environment.execInfo?.run.args ?? [];
1824
const allArgs = [...args, ...options.args];
19-
traceInfo(`Running in background: ${executable} ${allArgs.join(' ')}`);
25+
26+
// Log the command for debugging
27+
traceInfo(`Running in background: "${executable}" ${allArgs.join(' ')}`);
28+
29+
// Check if the file exists before trying to spawn it
30+
try {
31+
const fs = require('fs');
32+
if (!fs.existsSync(executable)) {
33+
traceError(
34+
`Python executable does not exist: ${executable}. Attempting to quote the path as a workaround...`,
35+
);
36+
executable = quoteStringIfNecessary(executable);
37+
}
38+
} catch (err) {
39+
traceWarn(`Error checking if executable exists: ${err instanceof Error ? err.message : String(err)}`);
40+
}
2041

2142
const proc = cp.spawn(executable, allArgs, { stdio: 'pipe', cwd: options.cwd, env: options.env });
2243

0 commit comments

Comments
 (0)