inetLatency() Windows fix parse chinese output
This commit is contained in:
parent
ad0d1c6cc0
commit
864a983aac
@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page.
|
|||||||
|
|
||||||
| Version | Date | Comment |
|
| Version | Date | Comment |
|
||||||
| -------------- | -------------- | -------- |
|
| -------------- | -------------- | -------- |
|
||||||
|
| 4.0.8 | 2019-02-05 | `inetLatency()` Windows fix parse chinese output |
|
||||||
| 4.0.7 | 2019-02-05 | `inetLatency()` Windows fix |
|
| 4.0.7 | 2019-02-05 | `inetLatency()` Windows fix |
|
||||||
| 4.0.6 | 2019-02-04 | powershell catch error |
|
| 4.0.6 | 2019-02-04 | powershell catch error |
|
||||||
| 4.0.5 | 2019-02-03 | updated docs |
|
| 4.0.5 | 2019-02-03 | updated docs |
|
||||||
|
|||||||
@ -80,9 +80,14 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">4.0.8</th>
|
||||||
|
<td>2019-02-05</td>
|
||||||
|
<td><span class="code">inetLatency()</span> latency fix parse chinese output</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">4.0.7</th>
|
<th scope="row">4.0.7</th>
|
||||||
<td>2019-02-06</td>
|
<td>2019-02-05</td>
|
||||||
<td><span class="code">inetLatency()</span> latency Windows fix</td>
|
<td><span class="code">inetLatency()</span> latency Windows fix</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@ -160,10 +160,10 @@ function inetLatency(host, callback) {
|
|||||||
let lines = stdout.toString().split('\r\n');
|
let lines = stdout.toString().split('\r\n');
|
||||||
lines.shift();
|
lines.shift();
|
||||||
lines.forEach(function (line) {
|
lines.forEach(function (line) {
|
||||||
if (line.toLowerCase().indexOf('ms,') > -1) {
|
if ((line.toLowerCase().match(/ms/g) || []).length === 3) {
|
||||||
let l = line.replace(/ +/g, ' ').split(' ');
|
let l = line.replace(/ +/g, ' ').split(' ');
|
||||||
if (l.length > 8) {
|
if (l.length > 6) {
|
||||||
result = parseFloat(l[9]);
|
result = parseFloat(l[l.length - 1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -220,7 +220,7 @@ function powerShell(cmd) {
|
|||||||
|
|
||||||
let result = '';
|
let result = '';
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve) => {
|
||||||
process.nextTick(() => {
|
process.nextTick(() => {
|
||||||
try {
|
try {
|
||||||
const child = spawn('powershell.exe', ['-NoLogo', '-InputFormat', 'Text', '-NoExit', '-ExecutionPolicy', 'Unrestricted', '-Command', '-'], {
|
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) {
|
child.stdout.on('data', function (data) {
|
||||||
result = result + data.toString('utf8');
|
result = result + data.toString('utf8');
|
||||||
});
|
});
|
||||||
child.stderr.on('data', function (data) {
|
child.stderr.on('data', function () {
|
||||||
child.kill();
|
child.kill();
|
||||||
resolve(result);
|
resolve(result);
|
||||||
});
|
});
|
||||||
@ -246,7 +246,7 @@ function powerShell(cmd) {
|
|||||||
try {
|
try {
|
||||||
child.stdin.write(cmd + os.EOL);
|
child.stdin.write(cmd + os.EOL);
|
||||||
child.stdin.write('exit' + os.EOL);
|
child.stdin.write('exit' + os.EOL);
|
||||||
child.stdin.end()
|
child.stdin.end();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
child.kill();
|
child.kill();
|
||||||
resolve(result);
|
resolve(result);
|
||||||
@ -260,6 +260,7 @@ function powerShell(cmd) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCodepage() {
|
function getCodepage() {
|
||||||
if (_windows) {
|
if (_windows) {
|
||||||
if (!codepage) {
|
if (!codepage) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user