Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #1282 use PYTHONIOENCODING variable #1291

Merged
merged 1 commit into from
Oct 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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