processes() fix parsing command and params

This commit is contained in:
Sebastian Hildebrandt
2020-05-03 08:02:08 +02:00
parent ba24765cfb
commit 7715043a42
4 changed files with 21 additions and 7 deletions
+14 -6
View File
@@ -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
});
}