diff --git a/CHANGELOG.md b/CHANGELOG.md index fa64db7..9053b7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -100,6 +100,7 @@ Other changes | Version | Date | Comment | | -------------- | -------------- | -------- | +| 3.42.5 | 2018-08-03 | `processes()` bugfix parsing ps linux | | 3.42.4 | 2018-07-09 | `cpuTemperature()` bugfix parsing negative values | | 3.42.3 | 2018-07-05 | `services()` bugfix not finding services with capital letters | | 3.42.2 | 2018-07-03 | `users()` optimized results if lack of permissions | diff --git a/lib/processes.js b/lib/processes.js index 1dea49c..2c30a18 100644 --- a/lib/processes.js +++ b/lib/processes.js @@ -217,7 +217,8 @@ function processes(callback) { let result = []; for (let i = 0; i < head.length; i++) { if (count <= rights) { - if (head[i] === ' ' && !space) { + // if (head[i] === ' ' && !space) { + if (/\s/.test(head[i]) && !space) { to = i - 1; result.push({ from: from, @@ -229,7 +230,7 @@ function processes(callback) { } space = head[i] === ' '; } else { - if (head[i] !== ' ' && space) { + if (/\s/.test(head[i]) && space) { to = i - 1; if (from < to) { result.push({ @@ -250,8 +251,18 @@ function processes(callback) { to: to, cap: head.substring(from, to) }); + let len = result.length; + for (var i = 0; i < len; i++) { + if (result[i].cap.replace(/\s/g, '').length === 0) { + if (i + 1 < len) { + result[i].to = result[i + 1].to; + result[i].cap = result[i].cap + result[i + 1].cap; + result.splice(i + 1, 1); + len = len - 1; + } + } + } return result; - } function getName(command) {