@@ -58,6 +58,8 @@ export interface CliCommandExecutor {
58
58
exec ( command : string , args : string [ ] , options ?: ExecOptions ) : Promise < CommandOutput >
59
59
}
60
60
61
+ const IS_WINDOWS : boolean = process . platform . startsWith ( 'win' ) ;
62
+
61
63
export class CliCommandExecutorImpl implements CliCommandExecutor {
62
64
private readonly logger : Logger ;
63
65
@@ -104,12 +106,11 @@ export class CliCommandExecutorImpl implements CliCommandExecutor {
104
106
105
107
let childProcess : cp . ChildProcessWithoutNullStreams ;
106
108
try {
107
- childProcess = cp . spawn ( command , args , {
108
- shell : process . platform . startsWith ( 'win' ) , // Use shell on Windows machines
109
- } ) ;
109
+ childProcess = IS_WINDOWS ? cp . spawn ( command , wrapArgsWithSpacesWithQuotes ( args ) , { shell : true } ) :
110
+ cp . spawn ( command , args ) ;
110
111
} catch ( err ) {
111
112
this . logger . logAtLevel ( vscode . LogLevel . Error , `Failed to execute the following command:\n` +
112
- indent ( `${ command } ${ args . map ( arg => arg . includes ( ' ' ) ? `" ${ arg } "` : arg ) . join ( ' ' ) } ` ) + `\n\n` +
113
+ indent ( `${ command } ${ wrapArgsWithSpacesWithQuotes ( args ) . join ( ' ' ) } ` ) + `\n\n` +
113
114
'Error Thrown:\n' + indent ( getErrorMessageWithStack ( err ) ) ) ;
114
115
output . stderr = getErrorMessageWithStack ( err ) ;
115
116
output . exitCode = 127 ;
@@ -123,7 +124,7 @@ export class CliCommandExecutorImpl implements CliCommandExecutor {
123
124
let combinedOut : string = '' ;
124
125
125
126
this . logger . logAtLevel ( logLevel , `Executing with background process (${ childProcess . pid } ):\n` +
126
- indent ( `${ command } ${ args . map ( arg => arg . includes ( ' ' ) ? `" ${ arg } "` : arg ) . join ( ' ' ) } ` ) ) ;
127
+ indent ( `${ command } ${ wrapArgsWithSpacesWithQuotes ( args ) . join ( ' ' ) } ` ) ) ;
127
128
128
129
childProcess . stdout . on ( 'data' , data => {
129
130
output . stdout += data ;
@@ -134,8 +135,10 @@ export class CliCommandExecutorImpl implements CliCommandExecutor {
134
135
combinedOut += data ;
135
136
} ) ;
136
137
childProcess . on ( 'error' , ( err : Error ) => {
138
+ const errMsg : string = getErrorMessageWithStack ( err ) ;
137
139
output . exitCode = 127 ; // 127 signifies that the command could not be executed
138
- output . stderr += getErrorMessageWithStack ( err ) ;
140
+ output . stderr += errMsg ;
141
+ combinedOut += errMsg ;
139
142
resolve ( output ) ;
140
143
this . logger . logAtLevel ( logLevel ,
141
144
`Error from background process (${ childProcess . pid } ):\n${ indent ( combinedOut ) } ` ) ;
@@ -149,3 +152,7 @@ export class CliCommandExecutorImpl implements CliCommandExecutor {
149
152
} ) ;
150
153
}
151
154
}
155
+
156
+ function wrapArgsWithSpacesWithQuotes ( args : string [ ] ) : string [ ] {
157
+ return args . map ( arg => arg . includes ( ' ' ) ? `"${ arg } "` : arg ) ;
158
+ }
0 commit comments