From 0ce0d3bf8be7e503515b31e779654acc19099b9e Mon Sep 17 00:00:00 2001 From: Bryan Roe Date: Wed, 3 Aug 2022 01:15:20 -0700 Subject: [PATCH] Added ability to search process on Windows --- modules/process-manager.js | 48 +++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/modules/process-manager.js b/modules/process-manager.js index f531bda..04246f7 100644 --- a/modules/process-manager.js +++ b/modules/process-manager.js @@ -349,24 +349,40 @@ function processManager() { return (JSON.parse(child.stdout.str.trim())); }; } - - this.getProcessEx = function getProcessEx(cmd) + } + this.getProcessEx = function getProcessEx(cmd) + { + if (process.platform == 'win32') { - var child = require('child_process').execFile('/bin/sh', ['sh']); - child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); }); - child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); }); - child.stdin.write('ps -ax -o pid -o command | grep ' + cmd + " | tr '\\n' '\\t' | awk -F" + '"\\t" \'{ printf "["; for(i=1;i1) { printf ","; } printf "%s", r[1]; } } printf "]"; }\''); - child.stdin.write('\nexit\n'); - child.waitExit(); + var result = []; + this.getProcesses(function (j) + { + var i; + for(i in j) + { + if(j[i].cmd.toLowerCase() == cmd.toLowerCase()) + { + result.push(j[i].pid); + } + } + }); + return (result); + } - if (child.stdout.str.trim() == '') - { - throw (cmd + ' not found'); - } - else - { - return (JSON.parse(child.stdout.str.trim())); - } + var child = require('child_process').execFile('/bin/sh', ['sh']); + child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); }); + child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); }); + child.stdin.write('ps -ax -o pid -o command | grep ' + cmd + " | tr '\\n' '\\t' | awk -F" + '"\\t" \'{ printf "["; for(i=1;i1) { printf ","; } printf "%s", r[1]; } } printf "]"; }\''); + child.stdin.write('\nexit\n'); + child.waitExit(); + + if (child.stdout.str.trim() == '') + { + throw (cmd + ' not found'); + } + else + { + return (JSON.parse(child.stdout.str.trim())); } } }