@@ -8,6 +8,7 @@ import * as path from "path";
8
8
import * as properties from "properties" ;
9
9
import * as vscode from "vscode" ;
10
10
import * as WinReg from "winreg" ;
11
+ import * as iconv from "iconv-lite" ;
11
12
12
13
/**
13
14
* This function will return the VSCode C/C++ extesnion compatible platform literals.
@@ -203,9 +204,38 @@ export function spawn(command: string, outputChannel: vscode.OutputChannel, args
203
204
options . cwd = options . cwd || path . resolve ( path . join ( __dirname , ".." ) ) ;
204
205
const child = childProcess . spawn ( command , args , options ) ;
205
206
207
+ let codepage = "65001" ;
208
+ if ( os . platform ( ) === "win32" ) {
209
+ codepage = childProcess . execSync ( 'chcp' ) . toString ( ) . split ( ':' ) . pop ( ) . trim ( ) ;
210
+ }
211
+
206
212
if ( outputChannel ) {
207
- child . stdout . on ( "data" , ( data ) => { outputChannel . append ( data . toString ( ) ) ; } ) ;
208
- child . stderr . on ( "data" , ( data ) => { outputChannel . append ( data . toString ( ) ) ; } ) ;
213
+ child . stdout . on ( "data" , ( data : Buffer ) => {
214
+ switch ( codepage ) {
215
+ case "932" :
216
+ outputChannel . append ( iconv . decode ( data , "Shift_JIS" ) ) ;
217
+ break ;
218
+ case "936" :
219
+ outputChannel . append ( iconv . decode ( data , "GBK" ) ) ;
220
+ break ;
221
+ default :
222
+ outputChannel . append ( data . toString ( ) ) ;
223
+ break ;
224
+ }
225
+ } ) ;
226
+ child . stderr . on ( "data" , ( data : Buffer ) => {
227
+ switch ( codepage ) {
228
+ case "932" :
229
+ outputChannel . append ( iconv . decode ( data , "Shift_JIS" ) ) ;
230
+ break ;
231
+ case "936" :
232
+ outputChannel . append ( iconv . decode ( data , "GBK" ) ) ;
233
+ break ;
234
+ default :
235
+ outputChannel . append ( data . toString ( ) ) ;
236
+ break ;
237
+ }
238
+ } ) ;
209
239
}
210
240
211
241
child . on ( "error" , ( error ) => reject ( { error, stderr, stdout } ) ) ;
0 commit comments