inetLatency() Windows fix parse chinese output
This commit is contained in:
+3
-3
@@ -160,10 +160,10 @@ function inetLatency(host, callback) {
|
||||
let lines = stdout.toString().split('\r\n');
|
||||
lines.shift();
|
||||
lines.forEach(function (line) {
|
||||
if (line.toLowerCase().indexOf('ms,') > -1) {
|
||||
if ((line.toLowerCase().match(/ms/g) || []).length === 3) {
|
||||
let l = line.replace(/ +/g, ' ').split(' ');
|
||||
if (l.length > 8) {
|
||||
result = parseFloat(l[9]);
|
||||
if (l.length > 6) {
|
||||
result = parseFloat(l[l.length - 1]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+4
-3
@@ -220,7 +220,7 @@ function powerShell(cmd) {
|
||||
|
||||
let result = '';
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
return new Promise((resolve) => {
|
||||
process.nextTick(() => {
|
||||
try {
|
||||
const child = spawn('powershell.exe', ['-NoLogo', '-InputFormat', 'Text', '-NoExit', '-ExecutionPolicy', 'Unrestricted', '-Command', '-'], {
|
||||
@@ -231,7 +231,7 @@ function powerShell(cmd) {
|
||||
child.stdout.on('data', function (data) {
|
||||
result = result + data.toString('utf8');
|
||||
});
|
||||
child.stderr.on('data', function (data) {
|
||||
child.stderr.on('data', function () {
|
||||
child.kill();
|
||||
resolve(result);
|
||||
});
|
||||
@@ -246,7 +246,7 @@ function powerShell(cmd) {
|
||||
try {
|
||||
child.stdin.write(cmd + os.EOL);
|
||||
child.stdin.write('exit' + os.EOL);
|
||||
child.stdin.end()
|
||||
child.stdin.end();
|
||||
} catch (e) {
|
||||
child.kill();
|
||||
resolve(result);
|
||||
@@ -260,6 +260,7 @@ function powerShell(cmd) {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getCodepage() {
|
||||
if (_windows) {
|
||||
if (!codepage) {
|
||||
|
||||
Reference in New Issue
Block a user