From 73b6281aab48218a464db96810ac7fd231163122 Mon Sep 17 00:00:00 2001 From: Shaun McPeck Date: Sun, 28 Jan 2018 13:35:56 -0600 Subject: [PATCH 1/2] Pass PID list into wmic query to speed things up on WIndows. --- lib/index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/index.js b/lib/index.js index 893c57b..36925d1 100644 --- a/lib/index.js +++ b/lib/index.js @@ -20,7 +20,7 @@ var SystemEOL = require('os').EOL; * @param {Object[]} callback.stdout */ -var Exec = module.exports = exports = function (args, callback) { +var Exec = module.exports = exports = function (winArgs, args, callback) { var spawn = ChildProcess.spawn; // on windows, if use ChildProcess.exec(`wmic process get`), the stdout will gives you nothing @@ -64,7 +64,7 @@ var Exec = module.exports = exports = function (args, callback) { callback(stderr, stdout.join(SystemEOL) || false); }); - CMD.stdin.write('wmic process get ProcessId,ParentProcessId,CommandLine \n'); + CMD.stdin.write('wmic process ' + winArgs.join(" ") + ' get ProcessId,ParentProcessId,CommandLine \n'); CMD.stdin.end(); } else { @@ -119,6 +119,7 @@ exports.lookup = function (query, callback) { * add 'lx' as default ps arguments, since the default ps output in linux like "ubuntu", wont include command arguments */ var exeArgs = query.psargs || ['lx']; + var winArgs; var filter = {}; var idList; @@ -131,7 +132,7 @@ exports.lookup = function (query, callback) { else { idList = [query.pid]; } - + winArgs = ["where", '"' + idList.map(pid => "ProcessId="+pid).join(" OR ") + '"']; // Cast all PIDs as Strings idList = idList.map(function (v) { return String(v); @@ -152,7 +153,7 @@ exports.lookup = function (query, callback) { filter['ppid'] = new RegExp(query.ppid); } - return Exec(exeArgs, function (err, output) { + return Exec(winArgs, exeArgs, function (err, output) { if (err) { return callback(err); } From 1ec451e15374d65da3f73a1acb83e0a5e5803612 Mon Sep 17 00:00:00 2001 From: Shaun McPeck Date: Sun, 28 Jan 2018 13:41:07 -0600 Subject: [PATCH 2/2] Default winArgs variable to empty array. --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 36925d1..fa49de2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -119,7 +119,7 @@ exports.lookup = function (query, callback) { * add 'lx' as default ps arguments, since the default ps output in linux like "ubuntu", wont include command arguments */ var exeArgs = query.psargs || ['lx']; - var winArgs; + var winArgs = []; var filter = {}; var idList;