@@ -460,10 +460,12 @@ public void onClose(int i, String s) {
460460 toggleStdout .disable ();
461461 OutputStream stdin = watch .getInput ();
462462 PrintStream in = new PrintStream (stdin , true , StandardCharsets .UTF_8 .name ());
463+ boolean windows = sh .equals ("cmd" );
463464 if (pwd != null ) {
464465 // We need to get into the project workspace.
465466 // The workspace is not known in advance, so we have to execute a cd command.
466- in .println (String .format ("cd \" %s\" " , pwd ));
467+ in .print (String .format ("cd \" %s\" " , pwd ));
468+ in .print (newLine (windows ));
467469 }
468470
469471 EnvVars envVars = new EnvVars ();
@@ -490,9 +492,9 @@ public void onClose(int i, String s) {
490492
491493 LOGGER .log (Level .FINEST , "Launching with env vars: {0}" , envVars .toString ());
492494
493- setupEnvironmentVariable (envVars , in , sh . equals ( "cmd" ) );
495+ setupEnvironmentVariable (envVars , in , windows );
494496
495- doExec (in , printStream , masks , commands );
497+ doExec (in , windows , printStream , masks , commands );
496498
497499 LOGGER .log (Level .INFO , "Created process inside pod: [" + getPodName () + "], container: ["
498500 + containerName + "]" + "[" + TimeUnit .NANOSECONDS .toMillis (System .nanoTime () - startMethod ) + " ms]" );
@@ -526,19 +528,24 @@ private void setupEnvironmentVariable(EnvVars vars, PrintStream out, boolean win
526528 for (Map .Entry <String , String > entry : vars .entrySet ()) {
527529 //Check that key is bash compliant.
528530 if (entry .getKey ().matches ("[a-zA-Z_][a-zA-Z0-9_]*" )) {
529- out .println (
531+ out .print (
530532 String .format (
531533 windows ? "set %s=%s" : "export %s='%s'" ,
532534 entry .getKey (),
533535 windows ? entry .getValue () : entry .getValue ().replace ("'" , "'\\ ''" )
534536 )
535537 );
538+ out .print (newLine (windows ));
536539 }
537540 }
538541 }
539542 };
540543 }
541544
545+ private static String newLine (boolean windows ) {
546+ return windows ? "\r \n " : "\n " ;
547+ }
548+
542549 @ Override
543550 public void close () throws IOException {
544551 if (closables == null ) return ;
@@ -617,7 +624,7 @@ private boolean isSeparator(int b) {
617624 }
618625 }
619626
620- private static void doExec (PrintStream in , PrintStream out , boolean [] masks , String ... statements ) {
627+ private static void doExec (PrintStream in , boolean windows , PrintStream out , boolean [] masks , String ... statements ) {
621628 long start = System .nanoTime ();
622629 // For logging
623630 ByteArrayOutputStream loggingOutput = new ByteArrayOutputStream ();
@@ -638,10 +645,11 @@ private static void doExec(PrintStream in, PrintStream out, boolean[] masks, Str
638645 .append (statements [i ])
639646 .append ("\" " );
640647 }
641- tee .println ( );
648+ tee .print ( newLine ( windows ) );
642649 LOGGER .log (Level .FINEST , loggingOutput .toString (encoding ) + "[" + TimeUnit .NANOSECONDS .toMicros (System .nanoTime () - start ) + " μs." + "]" );
643650 // We need to exit so that we know when the command has finished.
644- tee .println (EXIT );
651+ tee .print (EXIT );
652+ tee .print (newLine (windows ));
645653 tee .flush ();
646654 } catch (UnsupportedEncodingException e ) {
647655 e .printStackTrace ();
0 commit comments