Skip to content

Commit

Permalink
fix #1282 use PYTHONIOENCODING variable (#1291)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne authored Oct 10, 2017
1 parent 8d28c71 commit be9e535
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/client/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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<string> {
return new Promise<string>((resolve, reject) => {
options.env = options.env || {};
options.env['PYTHONIOENCODING'] = 'UTF-8';
let proc = child_process.spawn(file, args, options);
let error = '';
let exited = false;
Expand Down
13 changes: 12 additions & 1 deletion src/test/common/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit be9e535

Please sign in to comment.