Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be9e535

Browse files
authored
fix #1282 use PYTHONIOENCODING variable (DonJayamanne#1291)
1 parent 8d28c71 commit be9e535

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/client/common/utils.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export function execPythonFile(file: string, args: string[], cwd: string, includ
117117
// Cuz python interpreter is always a file and we can and will always run it using child_process.execFile()
118118
if (file === settings.PythonSettings.getInstance().pythonPath) {
119119
if (stdOut) {
120-
return spawnFileInternal(file, args, { cwd }, includeErrorAsResponse, stdOut, token);
120+
return spawnFileInternal(file, args, { cwd, env: customEnvVariables }, includeErrorAsResponse, stdOut, token);
121121
}
122122
if (execAsModule) {
123123
return getFullyQualifiedPythonInterpreterPath()
@@ -252,6 +252,8 @@ function execFileInternal(file: string, args: string[], options: child_process.E
252252
}
253253
function spawnFileInternal(file: string, args: string[], options: child_process.ExecFileOptions, includeErrorAsResponse: boolean, stdOut: (line: string) => void, token?: CancellationToken): Promise<string> {
254254
return new Promise<string>((resolve, reject) => {
255+
options.env = options.env || {};
256+
options.env['PYTHONIOENCODING'] = 'UTF-8';
255257
let proc = child_process.spawn(file, args, options);
256258
let error = '';
257259
let exited = false;

src/test/common/common.test.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,18 @@ suite('ChildProc', () => {
4444
}).then(done).catch(done);
4545
});
4646

47-
test('Stream Stdout with Threads', done => {
47+
test('Stream Stdout (Unicode)', async () => {
48+
const output: string[] = [];
49+
function handleOutput(data: string) {
50+
output.push(data);
51+
}
52+
await execPythonFile('python', ['-c', `print('öä')`], __dirname, false, handleOutput)
53+
assert.equal(output.length, 1, 'Ouput length incorrect');
54+
assert.equal(output[0], 'öä' + EOL, 'Ouput value incorrect');
55+
});
56+
57+
test('Stream Stdout with Threads', function (done) {
58+
this.timeout(6000);
4859
const output: string[] = [];
4960
function handleOutput(data: string) {
5061
output.push(data);

0 commit comments

Comments
 (0)