find-process
Advanced tools
Comparing version 1.4.6 to 1.4.7
1.4.7 / 2021-11-18 | ||
================== | ||
* chore: bump to 1.4.7 | ||
* fix: fix undefined issue [#40](http://github.com/yibn2008/find-process/issues/40) | ||
* fix: fix github actions | ||
* fix: fix install method | ||
1.4.6 / 2021-11-18 | ||
@@ -3,0 +11,0 @@ ================== |
/* | ||
* @Author: zoujie.wzj | ||
* @Date: 2016-01-23 18:25:37 | ||
* @Last Modified by: Ayon Lee | ||
* @Last Modified on: 2018-10-19 | ||
* @Last Modified by: Sahel LUCAS--SAOUDI | ||
* @Last Modified on: 2021-11-12 | ||
*/ | ||
@@ -123,6 +123,6 @@ | ||
return new Promise((resolve, reject) => { | ||
const cmd = 'WMIC path win32_process get Name,Processid,ParentProcessId,Commandline,ExecutablePath' | ||
const cmd = 'Get-CimInstance -className win32_process | select Name,ProcessId,ParentProcessId,CommandLine,ExecutablePath' | ||
const lines = [] | ||
const proc = utils.spawn('cmd', ['/c', cmd], { detached: false, windowsHide: true }) | ||
const proc = utils.spawn('powershell.exe', ['/c', cmd], { detached: false, windowsHide: true }) | ||
proc.stdout.on('data', data => { | ||
@@ -135,3 +135,3 @@ lines.push(data.toString()) | ||
} | ||
const list = utils.parseTable(lines.join('\n')) | ||
const list = utils.parseTable(lines.join('')) | ||
.filter(row => { | ||
@@ -141,7 +141,8 @@ if ('pid' in cond) { | ||
} else if (cond.name) { | ||
const rowName = row.Name || '' // fix #40 | ||
if (cond.strict) { | ||
return row.Name === cond.name || (row.Name.endsWith('.exe') && row.Name.slice(0, -4) === cond.name) | ||
return rowName === cond.name || (rowName.endsWith('.exe') && rowName.slice(0, -4) === cond.name) | ||
} else { | ||
// fix #9 | ||
return matchName(row.CommandLine || row.Name, cond.name) | ||
return matchName(row.CommandLine || rowName, cond.name) | ||
} | ||
@@ -158,3 +159,3 @@ } else { | ||
bin: row.ExecutablePath, | ||
name: row.Name, | ||
name: row.Name || '', | ||
cmd: row.CommandLine | ||
@@ -161,0 +162,0 @@ })) |
/* | ||
* @Author: zoujie.wzj | ||
* @Date: 2016-01-23 18:17:55 | ||
* @Last Modified by: Zoujie | ||
* @Last Modified time: 2016-02-04 17:16:58 | ||
* @Last Modified by: Sahel LUCAS--SAOUDI | ||
* @Last Modified on: 2021-11-12 | ||
*/ | ||
@@ -119,5 +119,9 @@ | ||
* ``` | ||
* Header1 Header2 Header3 | ||
* foo bar bar2 | ||
* valx valy valz | ||
* Header1 : foo | ||
* Header2 : bar | ||
* Header3 : val | ||
* | ||
* Header1 : foo2 | ||
* Header2 : bar2 | ||
* Header3 : val2 | ||
* ``` | ||
@@ -127,3 +131,3 @@ * | ||
* ``` | ||
* [{ Header1: 'foo', Header2: 'bar', Header3: 'bar2' }, ...] | ||
* [{ Header1: 'foo', Header2: 'bar', Header3: 'val' }, ...] | ||
* ``` | ||
@@ -135,35 +139,25 @@ * | ||
parseTable (data) { | ||
const lines = data.split(/(\r\n|\n|\r)/).filter(line => { | ||
const lines = data.split(/(\r\n\r\n|\r\n\n|\n\r\n)|\n\n/).filter(line => { | ||
return line.trim().length > 0 | ||
}) | ||
}).map((e) => e.split(/(\r\n|\n|\r)/).filter(line => line.trim().length > 0)) | ||
const matches = lines.shift().trim().match(/(\w+\s*)/g) | ||
if (!matches) { | ||
return [] | ||
} | ||
const ranges = [] | ||
const headers = matches.map((col, i) => { | ||
const range = [] | ||
if (i === 0) { | ||
range[0] = 0 | ||
range[1] = col.length | ||
} else { | ||
range[0] = ranges[i - 1][1] | ||
range[1] = range[0] + col.length | ||
// Join multi-ligne value | ||
lines.forEach((line) => { | ||
for (let index = 0; line[index];) { | ||
const entry = line[index] | ||
if (entry.startsWith(' ')) { | ||
line[index - 1] += entry.trimLeft() | ||
line.splice(index, 1) | ||
} else { | ||
index += 1 | ||
} | ||
} | ||
ranges.push(range) | ||
return col.trim() | ||
}) | ||
ranges[ranges.length - 1][1] = Infinity | ||
return lines.map(line => { | ||
const row = {} | ||
ranges.forEach((r, i) => { | ||
const key = headers[i] | ||
const value = line.substring(r[0], r[1]).trim() | ||
row[key] = value | ||
line.forEach((string) => { | ||
const splitterIndex = string.indexOf(':') | ||
const key = string.slice(0, splitterIndex).trim() | ||
row[key] = string.slice(splitterIndex + 1).trim() | ||
}) | ||
@@ -170,0 +164,0 @@ |
{ | ||
"name": "find-process", | ||
"version": "1.4.6", | ||
"version": "1.4.7", | ||
"description": "find process info by port/pid/name etc.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
28439
682