Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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);
}
Expand Down