@@ -371,7 +371,8 @@ class CustomBuildTaskTerminal implements Pseudoterminal {
371371
372372 private async doBuild ( ) : Promise < any > {
373373 // Do build.
374- let activeCommand : string = util . resolveVariables ( this . command ) ;
374+ let command : string = util . resolveVariables ( this . command ) ;
375+ let activeCommand : string = command ;
375376 this . args . forEach ( ( value , index ) => {
376377 value = util . normalizeArg ( util . resolveVariables ( value ) ) ;
377378 activeCommand = activeCommand + " " + value ;
@@ -387,15 +388,27 @@ class CustomBuildTaskTerminal implements Pseudoterminal {
387388 }
388389
389390 const splitWriteEmitter = ( lines : string | Buffer ) => {
390- for ( const line of lines . toString ( ) . split ( / \r ? \n / g) ) {
391- this . writeEmitter . fire ( line + this . endOfLine ) ;
391+ const splitLines : string [ ] = lines . toString ( ) . split ( / \r ? \n / g) ;
392+ for ( let i : number = 0 ; i < splitLines . length ; i ++ ) {
393+ let line : string = splitLines [ i ] ;
394+
395+ // We may not get full lines.
396+ // Only output an endOfLine when a full line is detected.
397+ if ( i !== splitLines . length - 1 ) {
398+ line += this . endOfLine ;
399+ }
400+ this . writeEmitter . fire ( line ) ;
392401 }
393402 } ;
394403
404+ if ( os . platform ( ) === 'win32' ) {
405+ command = `cmd /c chcp 65001>nul && ${ command } ` ;
406+ }
407+
395408 this . writeEmitter . fire ( activeCommand + this . endOfLine ) ;
396409 let child : cp . ChildProcess | undefined ;
397410 try {
398- child = cp . spawn ( this . command , this . args , this . options ? this . options : { } ) ;
411+ child = cp . spawn ( command , this . args , this . options ? this . options : { } ) ;
399412 let error : string = "" ;
400413 let stdout : string = "" ;
401414 let stderr : string = "" ;
@@ -407,16 +420,17 @@ class CustomBuildTaskTerminal implements Pseudoterminal {
407420 resolve ( - 1 ) ;
408421 } ) ;
409422 child . stdout ?. on ( 'data' , data => {
410- const str : string = data . toString ( "utf8" ) ;
423+ const str : string = data . toString ( ) ;
411424 splitWriteEmitter ( str ) ;
412425 stdout += str ;
413426 } ) ;
414427 child . stderr ?. on ( 'data' , data => {
415- const str : string = data . toString ( "utf8" ) ;
428+ const str : string = data . toString ( ) ;
416429 splitWriteEmitter ( str ) ;
417430 stderr += str ;
418431 } ) ;
419432 child . on ( 'close' , result => {
433+ this . writeEmitter . fire ( this . endOfLine ) ;
420434 if ( result === null ) {
421435 this . writeEmitter . fire ( localize ( "build.run.terminated" , "Build run was terminated." ) + this . endOfLine ) ;
422436 resolve ( - 1 ) ;
0 commit comments