Last active
June 14, 2018 07:19
-
-
Save khusamov/4a9d9f1219d06f4c47ab0043957577e8 to your computer and use it in GitHub Desktop.
Как правильно декодировать строку из 866 в UTF8, полученную из консоли дочернего процесса.
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
async function exec(command) { | |
const from = '866', to = 'utf8'; | |
const exec = Util.promisify(ChildProcess.exec); | |
const {stdout, stderr} = await exec(command, {encoding: 'buffer'}); | |
return { | |
stdout: Encoding.convert(stdout, to, from).toString(to), | |
stderr: Encoding.convert(stderr, to, from).toString(to) | |
}; | |
}; | |
const {stdout, stderr} = await exec(`dir`); |
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
import * as ChildProcess from 'child_process'; | |
import * as Util from "util"; | |
import * as Encoding from "encoding"; |
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
import * as Os from "os"; | |
import * as Path from "path"; | |
const tempFilePath = Path.join(Os.tmpdir(), '@TEMP', 'temp.txt'); | |
await writeFile(tempFilePath, stdout); | |
console.log(stdout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment