diff --git a/src/client/common/utils.ts b/src/client/common/utils.ts index bb3c0a2dd4bc..bd3fd3be17d1 100644 --- a/src/client/common/utils.ts +++ b/src/client/common/utils.ts @@ -117,7 +117,7 @@ export function execPythonFile(file: string, args: string[], cwd: string, includ // Cuz python interpreter is always a file and we can and will always run it using child_process.execFile() if (file === settings.PythonSettings.getInstance().pythonPath) { if (stdOut) { - return spawnFileInternal(file, args, { cwd }, includeErrorAsResponse, stdOut, token); + return spawnFileInternal(file, args, { cwd, env: customEnvVariables }, includeErrorAsResponse, stdOut, token); } if (execAsModule) { return getFullyQualifiedPythonInterpreterPath() @@ -252,6 +252,8 @@ function execFileInternal(file: string, args: string[], options: child_process.E } function spawnFileInternal(file: string, args: string[], options: child_process.ExecFileOptions, includeErrorAsResponse: boolean, stdOut: (line: string) => void, token?: CancellationToken): Promise { return new Promise((resolve, reject) => { + options.env = options.env || {}; + options.env['PYTHONIOENCODING'] = 'UTF-8'; let proc = child_process.spawn(file, args, options); let error = ''; let exited = false; diff --git a/src/test/common/common.test.ts b/src/test/common/common.test.ts index 3a53107f3c2d..2a04c3c2737f 100644 --- a/src/test/common/common.test.ts +++ b/src/test/common/common.test.ts @@ -44,7 +44,18 @@ suite('ChildProc', () => { }).then(done).catch(done); }); - test('Stream Stdout with Threads', done => { + test('Stream Stdout (Unicode)', async () => { + const output: string[] = []; + function handleOutput(data: string) { + output.push(data); + } + await execPythonFile('python', ['-c', `print('öä')`], __dirname, false, handleOutput) + assert.equal(output.length, 1, 'Ouput length incorrect'); + assert.equal(output[0], 'öä' + EOL, 'Ouput value incorrect'); + }); + + test('Stream Stdout with Threads', function (done) { + this.timeout(6000); const output: string[] = []; function handleOutput(data: string) { output.push(data);