@@ -357,15 +357,22 @@ private Proc doLaunch(boolean quiet, String[] cmdEnvs, OutputStream outputForCal
357357 stream = new TeeOutputStream (toggleStdout , printStream );
358358 }
359359
360- ByteArrayOutputStream dryRunCaller = new ByteArrayOutputStream () ;
361- ToggleOutputStream toggleDryRunCaller = new ToggleOutputStream ( dryRunCaller ) ;
360+ ByteArrayOutputStream dryRunCaller = null ; ;
361+ ToggleOutputStream toggleDryRunCaller = null ;
362362 ToggleOutputStream toggleOutputForCaller = null ;
363363 // Send to proc caller as well if they sent one
364364 if (outputForCaller != null && !outputForCaller .equals (printStream )) {
365- // Initially disable the output for the caller, to prevent it from getting unwanted output such as prompt
366- toggleOutputForCaller = new ToggleOutputStream (outputForCaller , true );
367- stream = new TeeOutputStream (toggleOutputForCaller , stream );
368- stream = new TeeOutputStream (toggleDryRunCaller , stream );
365+ if (launcher .isUnix ()) {
366+ stream = new TeeOutputStream (outputForCaller , stream );
367+ } else {
368+ // Prepare to capture output for later.
369+ dryRunCaller = new ByteArrayOutputStream ();
370+ toggleDryRunCaller = new ToggleOutputStream (dryRunCaller );
371+ // Initially disable the output for the caller, to prevent it from getting unwanted output such as prompt
372+ toggleOutputForCaller = new ToggleOutputStream (outputForCaller , true );
373+ stream = new TeeOutputStream (toggleOutputForCaller , stream );
374+ stream = new TeeOutputStream (toggleDryRunCaller , stream );
375+ }
369376 }
370377 ByteArrayOutputStream error = new ByteArrayOutputStream ();
371378
@@ -510,7 +517,13 @@ public void onClose(int i, String s) {
510517 Thread .sleep (100 );
511518 }
512519 LOGGER .log (Level .FINEST , "Windows prompt printed after " + (System .currentTimeMillis () - beginning ) + " ms" );
520+ }
521+ // We don't need to capture output anymore
522+ if (toggleDryRunCaller != null ) {
513523 toggleDryRunCaller .disable ();
524+ }
525+ // Clear any captured bytes
526+ if (dryRunCaller != null ) {
514527 dryRunCaller .reset ();
515528 }
516529 if (toggleOutputForCaller != null ) {
0 commit comments