processes() fix command line parsing (win) wip
This commit is contained in:
parent
1ef846c4ee
commit
1512eabec1
@ -934,40 +934,32 @@ function processes(callback) {
|
||||
try {
|
||||
util
|
||||
.powerShell(
|
||||
'Get-CimInstance Win32_Process | select-Object ProcessId,ParentProcessId,ExecutionState,Caption,CommandLine,ExecutablePath,UserModeTime,KernelModeTime,WorkingSetSize,Priority,PageFileUsage, @{n="CreationDate";e={$_.CreationDate.ToString("yyyy-MM-dd HH:mm:ss")}} | fl'
|
||||
'Get-CimInstance Win32_Process | select-Object ProcessId,ParentProcessId,ExecutionState,Caption,CommandLine,ExecutablePath,UserModeTime,KernelModeTime,WorkingSetSize,Priority,PageFileUsage, @{n="CreationDate";e={$_.CreationDate.ToString("yyyy-MM-dd HH:mm:ss")}} | ConvertTo-Json -compress'
|
||||
)
|
||||
.then((stdout, error) => {
|
||||
if (!error) {
|
||||
let processSections = stdout.split(/\n\s*\n/);
|
||||
let procs = [];
|
||||
let procStats = [];
|
||||
let list_new = {};
|
||||
const procs = [];
|
||||
const procStats = [];
|
||||
const list_new = {};
|
||||
let allcpuu = 0;
|
||||
let allcpus = 0;
|
||||
processSections.forEach((element) => {
|
||||
let processArray = [];
|
||||
try {
|
||||
stdout = stdout.trim().replace(/^\uFEFF/, '');
|
||||
processArray = JSON.parse(stdout);
|
||||
} catch {}
|
||||
processArray.forEach((element) => {
|
||||
if (element.trim() !== '') {
|
||||
let lines = element.trim().split('\r\n');
|
||||
let pid = parseInt(util.getValue(lines, 'ProcessId', ':', true), 10);
|
||||
let parentPid = parseInt(util.getValue(lines, 'ParentProcessId', ':', true), 10);
|
||||
let statusValue = util.getValue(lines, 'ExecutionState', ':');
|
||||
let name = util.getValue(lines, 'Caption', ':', true);
|
||||
let commandLine = util.getValue(lines, 'CommandLine', ':', true);
|
||||
const pid = element.ProcessId;
|
||||
const parentPid = element.ParentProcessId;
|
||||
const statusValue = element.ExecutionState || null;
|
||||
const name = element.Caption;
|
||||
const commandLine = element.CommandLine;
|
||||
// get additional command line data
|
||||
let additionalCommand = false;
|
||||
lines.forEach((line) => {
|
||||
if (additionalCommand && line.toLowerCase().startsWith(' ')) {
|
||||
commandLine += ' ' + line.trim();
|
||||
} else {
|
||||
additionalCommand = false;
|
||||
}
|
||||
if (line.toLowerCase().startsWith('commandline')) {
|
||||
additionalCommand = true;
|
||||
}
|
||||
});
|
||||
let commandPath = util.getValue(lines, 'ExecutablePath', ':', true);
|
||||
let utime = parseInt(util.getValue(lines, 'UserModeTime', ':', true), 10);
|
||||
let stime = parseInt(util.getValue(lines, 'KernelModeTime', ':', true), 10);
|
||||
let memw = parseInt(util.getValue(lines, 'WorkingSetSize', ':', true), 10);
|
||||
const commandPath = element.ExecutablePath;
|
||||
const utime = element.UserModeTime;
|
||||
const stime = element.KernelModeTime;
|
||||
const memw = element.WorkingSetSize;
|
||||
allcpuu = allcpuu + utime;
|
||||
allcpus = allcpus + stime;
|
||||
result.all++;
|
||||
@ -997,12 +989,12 @@ function processes(callback) {
|
||||
cpuu: 0,
|
||||
cpus: 0,
|
||||
mem: (memw / os.totalmem()) * 100,
|
||||
priority: parseInt(util.getValue(lines, 'Priority', ':', true), 10),
|
||||
memVsz: parseInt(util.getValue(lines, 'PageFileUsage', ':', true), 10),
|
||||
memRss: Math.floor(parseInt(util.getValue(lines, 'WorkingSetSize', ':', true), 10) / 1024),
|
||||
priority: element.Priority | null,
|
||||
memVsz: element.PageFileUsage || null,
|
||||
memRss: Math.floor((element.WorkingSetSize || 0) / 1024),
|
||||
nice: 0,
|
||||
started: util.getValue(lines, 'CreationDate', ':', true),
|
||||
state: !statusValue ? _winStatusValues[0] : _winStatusValues[statusValue],
|
||||
started: element.CreationDate,
|
||||
state: statusValue ? _winStatusValues[statusValue] : _winStatusValues[0],
|
||||
tty: '',
|
||||
user: '',
|
||||
command: commandLine || name,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user