@@ -15,6 +15,7 @@ import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
15
15
import { createWaitMarkerFileSync } from 'vs/platform/environment/node/wait' ;
16
16
import { PipeCommand } from 'vs/workbench/api/node/extHostCLIServer' ;
17
17
import { hasStdinWithoutTty , getStdinFilePath , readFromStdin } from 'vs/platform/environment/node/stdin' ;
18
+ import { DeferredPromise } from 'vs/base/common/async' ;
18
19
19
20
/*
20
21
* Implements a standalone CLI app that opens VS Code from a remote terminal.
@@ -181,26 +182,33 @@ export async function main(desc: ProductDescription, args: string[]): Promise<vo
181
182
182
183
parsedArgs [ '_' ] = [ ] ;
183
184
185
+ let readFromStdinPromise : Promise < void > | undefined ;
186
+
184
187
if ( hasReadStdinArg && hasStdinWithoutTty ( ) ) {
185
188
try {
186
189
let stdinFilePath = cliStdInFilePath ;
187
190
if ( ! stdinFilePath ) {
188
191
stdinFilePath = getStdinFilePath ( ) ;
189
- await readFromStdin ( stdinFilePath , verbose ) ; // throws error if file can not be written
192
+ const readFromStdinDone = new DeferredPromise < void > ( ) ;
193
+ await readFromStdin ( stdinFilePath , verbose , ( ) => readFromStdinDone . complete ( ) ) ; // throws error if file can not be written
194
+ if ( ! parsedArgs . wait ) {
195
+ // if `--wait` is not provided, we keep this process alive
196
+ // for at least as long as the stdin stream is open to
197
+ // ensure that we read all the data.
198
+ readFromStdinPromise = readFromStdinDone . p ;
199
+ }
190
200
}
191
201
192
202
// Make sure to open tmp file
193
203
translatePath ( stdinFilePath , mapFileUri , folderURIs , fileURIs ) ;
194
204
195
- // Enable --wait to get all data and ignore adding this to history
196
- parsedArgs . wait = true ;
205
+ // Ignore adding this to history
197
206
parsedArgs [ 'skip-add-to-recently-opened' ] = true ;
198
207
199
208
console . log ( `Reading from stdin via: ${ stdinFilePath } ` ) ;
200
209
} catch ( e ) {
201
210
console . log ( `Failed to create file to read via stdin: ${ e . toString ( ) } ` ) ;
202
211
}
203
-
204
212
}
205
213
206
214
if ( parsedArgs . extensionDevelopmentPath ) {
@@ -339,6 +347,10 @@ export async function main(desc: ProductDescription, args: string[]): Promise<vo
339
347
if ( waitMarkerFilePath ) {
340
348
waitForFileDeleted ( waitMarkerFilePath ) ;
341
349
}
350
+
351
+ if ( readFromStdinPromise ) {
352
+ await readFromStdinPromise ;
353
+ }
342
354
}
343
355
}
344
356
0 commit comments