@@ -185,6 +185,8 @@ internal NativeCommandProcessor(ApplicationInfo applicationInfo, ExecutionContex
185
185
186
186
//Create input writer for providing input to the process.
187
187
_inputWriter = new ProcessInputWriter ( Command ) ;
188
+
189
+ _isTranscribing = this . Command . Context . EngineHostInterface . UI . IsTranscribing ;
188
190
}
189
191
190
192
/// <summary>
@@ -373,8 +375,8 @@ internal override void ProcessRecord()
373
375
/// </summary>
374
376
private BlockingCollection < ProcessOutputObject > _nativeProcessOutputQueue ;
375
377
376
- private bool _scrapeHostOutput ;
377
-
378
+ private static bool ? s_supportScreenScrape = null ;
379
+ private bool _isTranscribing ;
378
380
private Host . Coordinates _startPosition ;
379
381
380
382
/// <summary>
@@ -398,11 +400,13 @@ private void InitNativeProcess()
398
400
// redirecting anything. This is a bit tricky as we always run redirected so
399
401
// we have to see if the redirection is actually being done at the topmost level or not.
400
402
401
- //Calculate if input and output are redirected.
403
+ // Calculate if input and output are redirected.
402
404
bool redirectOutput ;
403
405
bool redirectError ;
404
406
bool redirectInput ;
405
407
408
+ _startPosition = new Host . Coordinates ( ) ;
409
+
406
410
CalculateIORedirection ( out redirectOutput , out redirectError , out redirectInput ) ;
407
411
408
412
// Find out if it's the only command in the pipeline.
@@ -416,9 +420,6 @@ private void InitNativeProcess()
416
420
throw new PipelineStoppedException ( ) ;
417
421
}
418
422
419
- _startPosition = new Host . Coordinates ( ) ;
420
- _scrapeHostOutput = false ;
421
-
422
423
Exception exceptionToRethrow = null ;
423
424
try
424
425
{
@@ -432,19 +433,10 @@ private void InitNativeProcess()
432
433
433
434
// Also, store the Raw UI coordinates so that we can scrape the screen after
434
435
// if we are transcribing.
435
- try
436
+ if ( _isTranscribing && ( true == s_supportScreenScrape ) )
436
437
{
437
- if ( this . Command . Context . EngineHostInterface . UI . IsTranscribing )
438
- {
439
- _scrapeHostOutput = true ;
440
- _startPosition = this . Command . Context . EngineHostInterface . UI . RawUI . CursorPosition ;
441
- _startPosition . X = 0 ;
442
- }
443
- }
444
- catch ( Host . HostException )
445
- {
446
- // The host doesn't support scraping via its RawUI interface
447
- _scrapeHostOutput = false ;
438
+ _startPosition = this . Command . Context . EngineHostInterface . UI . RawUI . CursorPosition ;
439
+ _startPosition . X = 0 ;
448
440
}
449
441
}
450
442
@@ -697,9 +689,8 @@ internal override void Complete()
697
689
ConsumeAvailableNativeProcessOutput ( blocking : true ) ;
698
690
_nativeProcess . WaitForExit ( ) ;
699
691
700
- // Capture screen output if we are transcribing
701
- if ( this . Command . Context . EngineHostInterface . UI . IsTranscribing &&
702
- _scrapeHostOutput )
692
+ // Capture screen output if we are transcribing and running stand alone
693
+ if ( _isTranscribing && ( true == s_supportScreenScrape ) && _runStandAlone )
703
694
{
704
695
Host . Coordinates endPosition = this . Command . Context . EngineHostInterface . UI . RawUI . CursorPosition ;
705
696
endPosition . X = this . Command . Context . EngineHostInterface . UI . RawUI . BufferSize . Width - 1 ;
@@ -1287,6 +1278,33 @@ private void CalculateIORedirection(out bool redirectOutput, out bool redirectEr
1287
1278
}
1288
1279
1289
1280
_runStandAlone = ! redirectInput && ! redirectOutput && ! redirectError ;
1281
+
1282
+ if ( _runStandAlone )
1283
+ {
1284
+ if ( null == s_supportScreenScrape )
1285
+ {
1286
+ try
1287
+ {
1288
+ _startPosition = this . Command . Context . EngineHostInterface . UI . RawUI . CursorPosition ;
1289
+ Host . BufferCell [ , ] bufferContents = this . Command . Context . EngineHostInterface . UI . RawUI . GetBufferContents (
1290
+ new Host . Rectangle ( _startPosition , _startPosition ) ) ;
1291
+ s_supportScreenScrape = true ;
1292
+ }
1293
+ catch ( Exception )
1294
+ {
1295
+ s_supportScreenScrape = false ;
1296
+ }
1297
+ }
1298
+
1299
+ // if screen scraping isn't supported, we enable redirection so that the output is still transcribed
1300
+ // as redirected output is always transcribed
1301
+ if ( _isTranscribing && ( false == s_supportScreenScrape ) )
1302
+ {
1303
+ redirectOutput = true ;
1304
+ redirectError = true ;
1305
+ _runStandAlone = false ;
1306
+ }
1307
+ }
1290
1308
}
1291
1309
1292
1310
private bool ValidateExtension ( string path )
0 commit comments