1
1
import { Terminal , TerminalShellExecution } from 'vscode' ;
2
2
import { PythonEnvironment , PythonTerminalExecutionOptions } from '../../api' ;
3
- import { onDidEndTerminalShellExecution } from '../../common/window.apis' ;
4
3
import { createDeferred } from '../../common/utils/deferred' ;
5
- import { quoteArgs } from '../execution/execUtils' ;
6
- import { identifyTerminalShell } from '../common/shellDetector' ;
4
+ import { onDidEndTerminalShellExecution } from '../../common/window.apis' ;
7
5
import { ShellConstants } from '../common/shellConstants' ;
6
+ import { identifyTerminalShell } from '../common/shellDetector' ;
7
+ import { quoteArgs } from '../execution/execUtils' ;
8
8
9
9
export async function runInTerminal (
10
10
environment : PythonEnvironment ,
@@ -15,11 +15,10 @@ export async function runInTerminal(
15
15
terminal . show ( ) ;
16
16
}
17
17
18
- const executable =
19
- environment . execInfo ?. activatedRun ?. executable ?? environment . execInfo ?. run . executable ?? 'python' ;
18
+ let executable = environment . execInfo ?. activatedRun ?. executable ?? environment . execInfo ?. run . executable ?? 'python' ;
20
19
const args = environment . execInfo ?. activatedRun ?. args ?? environment . execInfo ?. run . args ?? [ ] ;
21
20
const allArgs = [ ...args , ...( options . args ?? [ ] ) ] ;
22
-
21
+ const shellType = identifyTerminalShell ( terminal ) ;
23
22
if ( terminal . shellIntegration ) {
24
23
let execution : TerminalShellExecution | undefined ;
25
24
const deferred = createDeferred < void > ( ) ;
@@ -29,10 +28,21 @@ export async function runInTerminal(
29
28
deferred . resolve ( ) ;
30
29
}
31
30
} ) ;
31
+
32
+ const shouldSurroundWithQuotes =
33
+ executable . includes ( ' ' ) && ! executable . startsWith ( '"' ) && ! executable . endsWith ( '"' ) ;
34
+ // Handle case where executable contains white-spaces.
35
+ if ( shouldSurroundWithQuotes ) {
36
+ executable = `"${ executable } "` ;
37
+ }
38
+
39
+ if ( shellType === ShellConstants . PWSH && ! executable . startsWith ( '&' ) ) {
40
+ // PowerShell requires commands to be prefixed with '&' to run them.
41
+ executable = `& ${ executable } ` ;
42
+ }
32
43
execution = terminal . shellIntegration . executeCommand ( executable , allArgs ) ;
33
44
await deferred . promise ;
34
45
} else {
35
- const shellType = identifyTerminalShell ( terminal ) ;
36
46
let text = quoteArgs ( [ executable , ...allArgs ] ) . join ( ' ' ) ;
37
47
if ( shellType === ShellConstants . PWSH && ! text . startsWith ( '&' ) ) {
38
48
// PowerShell requires commands to be prefixed with '&' to run them.
0 commit comments