This repository has been archived by the owner on Oct 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 228
win32 platform support not utf8 encoding at childProcess.spawn() stdout/stderr #364
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
import * as childProcess from "child_process"; | ||
import * as fs from "fs"; | ||
import * as iconv from "iconv-lite"; | ||
import * as os from "os"; | ||
import * as path from "path"; | ||
import * as properties from "properties"; | ||
|
@@ -203,9 +204,38 @@ export function spawn(command: string, outputChannel: vscode.OutputChannel, args | |
options.cwd = options.cwd || path.resolve(path.join(__dirname, "..")); | ||
const child = childProcess.spawn(command, args, options); | ||
|
||
let codepage = "65001"; | ||
if (os.platform() === "win32") { | ||
codepage = childProcess.execSync("chcp").toString().split(":").pop().trim(); | ||
} | ||
|
||
if (outputChannel) { | ||
child.stdout.on("data", (data) => { outputChannel.append(data.toString()); }); | ||
child.stderr.on("data", (data) => { outputChannel.append(data.toString()); }); | ||
child.stdout.on("data", (data: Buffer) => { | ||
switch (codepage) { | ||
case "932": | ||
outputChannel.append(iconv.decode(data, "Shift_JIS")); | ||
break; | ||
case "936": | ||
outputChannel.append(iconv.decode(data, "GBK")); | ||
break; | ||
default: | ||
outputChannel.append(data.toString()); | ||
break; | ||
} | ||
}); | ||
child.stderr.on("data", (data: Buffer) => { | ||
switch (codepage) { | ||
case "932": | ||
outputChannel.append(iconv.decode(data, "Shift_JIS")); | ||
break; | ||
case "936": | ||
outputChannel.append(iconv.decode(data, "GBK")); | ||
break; | ||
default: | ||
outputChannel.append(data.toString()); | ||
break; | ||
} | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To avoid the duplication, the code is better to implement on the outputChannel side. |
||
} | ||
|
||
child.on("error", (error) => reject({ error, stderr, stdout })); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this, I would suggest use a config file called (codepageMapping.json) which we can put under ./msci folder as mapping files. (The folder name might be changed later.)
If can find the codepage from the mapping, just convert it. Otherwise use the default one.