Skip to content

Instantly share code, notes, and snippets.

@khusamov
Last active June 14, 2018 07:19
Show Gist options
  • Save khusamov/4a9d9f1219d06f4c47ab0043957577e8 to your computer and use it in GitHub Desktop.
Save khusamov/4a9d9f1219d06f4c47ab0043957577e8 to your computer and use it in GitHub Desktop.
Как правильно декодировать строку из 866 в UTF8, полученную из консоли дочернего процесса.
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`);
import * as ChildProcess from 'child_process';
import * as Util from "util";
import * as Encoding from "encoding";
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