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 |
|
||||
| -------------- | -------------- | -------- |
|
||||
| 4.0.8 | 2019-02-05 | `inetLatency()` Windows fix parse chinese output |
|
||||
| 4.0.7 | 2019-02-05 | `inetLatency()` Windows fix |
|
||||
| 4.0.6 | 2019-02-04 | powershell catch error |
|
||||
| 4.0.5 | 2019-02-03 | updated docs |
|
||||
|
||||
@ -80,9 +80,14 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<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>
|
||||
<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>
|
||||
</tr>
|
||||
<tr>
|
||||
|
||||
@ -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]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user