diff --git a/lib/util.js b/lib/util.js index 25b8375..04571ad 100644 --- a/lib/util.js +++ b/lib/util.js @@ -218,24 +218,10 @@ function getWmic() { function powerShell(cmd) { - // helper function - function dispose(child) { - return new Promise((resolve, reject) => { - child.stdin.write('exit' + os.EOL); - process.nextTick(() => { - child.stdin.end() - child.kill(); - resolve(); - }); - }) - } - let result = ''; return new Promise((resolve, reject) => { - process.nextTick(() => { - try { const child = spawn('powershell.exe', ['-NoLogo', '-InputFormat', 'Text', '-NoExit', '-ExecutionPolicy', 'Unrestricted', '-Command', '-'], { stdio: 'pipe' @@ -246,20 +232,24 @@ function powerShell(cmd) { result = result + data.toString('utf8'); }); child.stderr.on('data', function (data) { - dispose(child).then(resolve(result)); + child.kill(); + resolve(result); }); child.on('close', function () { - dispose(child).then(resolve(result)); - ; + child.kill(); + resolve(result); }); child.on('error', function () { - dispose(child).then(resolve(result)); + child.kill(); + resolve(result); }); - try { child.stdin.write(cmd + os.EOL); + child.stdin.write('exit' + os.EOL); + child.stdin.end() } catch (e) { - dispose(child).then(resolve(result)); + child.kill(); + resolve(result); } } else { resolve(result); @@ -270,7 +260,6 @@ function powerShell(cmd) { }); }); } - function getCodepage() { if (_windows) { if (!codepage) {