From b4cd550b160f4428958c4c92e8ff4af37fd79792 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Sat, 9 Oct 2021 08:22:39 +0200 Subject: [PATCH] Win Powershell UTF8 support --- lib/users.js | 2 +- lib/util.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/users.js b/lib/users.js index bcd4587..cdbc3ca 100644 --- a/lib/users.js +++ b/lib/users.js @@ -283,7 +283,7 @@ function users(callback) { } if (_windows) { try { - util.execWin('query user', util.execOptsWin, function (error, stdout) { + util.powerShell('query user').then(stdout => { if (stdout) { // lines / split let lines = stdout.toString().split('\r\n'); diff --git a/lib/util.js b/lib/util.js index 68ccfb8..94a30be 100644 --- a/lib/util.js +++ b/lib/util.js @@ -341,6 +341,7 @@ function getVboxmanage() { function powerShell(cmd) { let result = ''; + const psUTF8 = '$OutputEncoding = [System.Console]::OutputEncoding = [System.Console]::InputEncoding = [System.Text.Encoding]::UTF8 ; '; return new Promise((resolve) => { process.nextTick(() => { @@ -375,7 +376,7 @@ function powerShell(cmd) { resolve(result); }); try { - child.stdin.write(cmd + os.EOL); + child.stdin.write(psUTF8 + cmd + os.EOL); child.stdin.write('exit' + os.EOL); child.stdin.end(); } catch (e) {