From 7715043a4226ec6864c840109fd72c0fc3e726a2 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Sun, 3 May 2020 08:02:08 +0200 Subject: [PATCH] processes() fix parsing command and params --- CHANGELOG.md | 1 + docs/history.html | 5 +++++ docs/index.html | 2 +- lib/processes.js | 20 ++++++++++++++------ 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c398a20..10d5ece 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page. | Version | Date | Comment | | -------------- | -------------- | -------- | +| 4.24.1 | 2020-05-03 | `processes()` fix parsing command and params | | 4.24.0 | 2020-05-01 | `networkInterfaces()` added subnet mask ip4 and ip6 | | 4.23.10 | 2020-05-01 | `cpuTemperature()` optimized parsing linux | | 4.23.9 | 2020-04-29 | `currentLoad()` workarround for no os.cpus info | diff --git a/docs/history.html b/docs/history.html index f8f9e4a..a1d7205 100644 --- a/docs/history.html +++ b/docs/history.html @@ -83,6 +83,11 @@ + + 4.24.1 + 2020-05-03 + processes() fix parsing command and params (linux, macOS) /td> + 4.24.0 2020-05-01 diff --git a/docs/index.html b/docs/index.html index 26e3710..b904529 100644 --- a/docs/index.html +++ b/docs/index.html @@ -168,7 +168,7 @@
systeminformation
-
Current Version: 4.24.0
+
Current Version: 4.24.1
diff --git a/lib/processes.js b/lib/processes.js index 075a216..8f883a9 100644 --- a/lib/processes.js +++ b/lib/processes.js @@ -14,6 +14,8 @@ // ---------------------------------------------------------------------------------- const os = require('os'); +const fs = require('fs'); +const path = require('path'); const exec = require('child_process').exec; const execSync = require('child_process').execSync; @@ -436,6 +438,7 @@ function processes(callback) { } function parseLine(line) { + let offset = 0; let offset2 = 0; @@ -472,7 +475,7 @@ function processes(callback) { const user = line.substring(parsedhead[11].from + offset, parsedhead[11].to + offset2).trim(); checkColumn(12); const fullcommand = line.substring(parsedhead[12].from + offset, parsedhead[12].to + offset2).trim().replace(/\[/g, '').replace(/]/g, ''); - let path = ''; + let cmdPath = ''; let command = ''; let params = ''; // try to figure out where parameter starts @@ -485,14 +488,19 @@ function processes(callback) { const tmpParams = fullcommand.substr(firstPos); const lastSlashPos = tmpCommand.lastIndexOf('/'); if (lastSlashPos >= 0) { - path = tmpCommand.substr(0, lastSlashPos); + cmdPath = tmpCommand.substr(0, lastSlashPos); tmpCommand = tmpCommand.substr(lastSlashPos + 1); } - if (firstPos === 10000) { + if (firstPos === 10000 && tmpCommand.indexOf(' ') > -1) { const parts = tmpCommand.split(' '); - command = parts.shift(); - params = (parts.join(' ') + ' ' + tmpParams).trim(); + if (fs.existsSync(path.join(cmdPath, parts[0]))) { + command = parts.shift(); + params = (parts.join(' ') + ' ' + tmpParams).trim(); + } else { + command = tmpCommand.trim(); + params = tmpParams.trim(); + } } else { command = tmpCommand.trim(); params = tmpParams.trim(); @@ -516,7 +524,7 @@ function processes(callback) { user: user, command: command, params: params, - path: path + path: cmdPath }); }