Skip to content

Commit e3dd50e

Browse files
authored
fix: use '&' when sending commands using sendtext to powershell (#262)
Fixes #257
1 parent 590cf28 commit e3dd50e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/features/terminal/runInTerminal.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { PythonEnvironment, PythonTerminalExecutionOptions } from '../../api';
33
import { onDidEndTerminalShellExecution } from '../../common/window.apis';
44
import { createDeferred } from '../../common/utils/deferred';
55
import { quoteArgs } from '../execution/execUtils';
6+
import { identifyTerminalShell } from '../common/shellDetector';
67

78
export async function runInTerminal(
89
environment: PythonEnvironment,
@@ -28,9 +29,14 @@ export async function runInTerminal(
2829
}
2930
});
3031
execution = terminal.shellIntegration.executeCommand(executable, allArgs);
31-
return deferred.promise;
32+
await deferred.promise;
3233
} else {
33-
const text = quoteArgs([executable, ...allArgs]).join(' ');
34+
const shellType = identifyTerminalShell(terminal);
35+
let text = quoteArgs([executable, ...allArgs]).join(' ');
36+
if (shellType === 'pwsh' && !text.startsWith('&')) {
37+
// PowerShell requires commands to be prefixed with '&' to run them.
38+
text = `& ${text}`;
39+
}
3440
terminal.sendText(`${text}\n`);
3541
}
3642
}

0 commit comments

Comments
 (0)