Skip to content

Commit f28db5d

Browse files
authored
Fix encoding (#394)
* fix encoding issue
1 parent 8d79301 commit f28db5d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/client/common/process/proc.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ export class ProcessService implements IProcessService {
2222

2323
// Always ensure we have unbuffered output.
2424
spawnOptions.env.PYTHONUNBUFFERED = '1';
25+
if (!spawnOptions.env.PYTHONIOENCODING) {
26+
spawnOptions.env.PYTHONIOENCODING = 'utf-8';
27+
}
2528

2629
const proc = spawn(file, args, spawnOptions);
2730
let procExited = false;
@@ -78,7 +81,9 @@ export class ProcessService implements IProcessService {
7881

7982
// Always ensure we have unbuffered output.
8083
spawnOptions.env.PYTHONUNBUFFERED = '1';
81-
84+
if (!spawnOptions.env.PYTHONIOENCODING) {
85+
spawnOptions.env.PYTHONIOENCODING = 'utf-8';
86+
}
8287
const proc = spawn(file, args, spawnOptions);
8388
const deferred = createDeferred<ExecutionResult<string>>();
8489
const disposables: Disposable[] = [];

src/test/common/process/proc.exec.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ suite('ProcessService', () => {
3232
expect(result.stderr).to.equal(undefined, 'stderr not undefined');
3333
});
3434

35+
test('exec should output print unicode characters', async () => {
36+
const procService = new ProcessService(new BufferDecoder());
37+
const printOutput = 'öä';
38+
const result = await procService.exec(pythonPath, ['-c', `print(u"${printOutput}")`]);
39+
40+
expect(result).not.to.be.an('undefined', 'result is undefined');
41+
expect(result.stdout.trim()).to.be.equal(printOutput, 'Invalid output');
42+
expect(result.stderr).to.equal(undefined, 'stderr not undefined');
43+
});
44+
3545
test('exec should wait for completion of program with new lines', async function () {
3646
// tslint:disable-next-line:no-invalid-this
3747
this.timeout(5000);

0 commit comments

Comments
 (0)