1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-30 23:23:32 +00:00

Fixed bug, where pgrep was initialized on Win32

This commit is contained in:
Bryan Roe
2019-11-21 14:46:59 -08:00
parent bca47688ff
commit 58e9d3f24d
2 changed files with 30 additions and 30 deletions

View File

@@ -190,37 +190,37 @@ function processManager() {
}
};
Object.defineProperty(this, '_pgrep', {
value: (function ()
{
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = '';
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
child.stdin.write("whereis pgrep | awk '{ print $2 }'\nexit\n");
child.waitExit();
return (child.stdout.str.trim());
})()
});
if(this._pgrep != '')
{
this.getProcess = function getProcess(cmd)
{
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("pgrep gnome-session | tr '\\n' '\\t' |" + ' awk -F"\\t" \'{ printf "["; for(i=1;i<NF;++i) { if(i>1) { printf ","; } printf "%d", $i; } printf "]"; }\'');
child.stdin.write('\nexit\n');
child.waitExit();
if (child.stderr.str != '') { throw (child.stderr.str.trim()); }
if (child.stdout.str.trim() == '') { throw (cmd + ' not found'); }
return (JSON.parse(child.stdout.str.trim()));
};
}
if(process.platform != 'win32')
{
Object.defineProperty(this, '_pgrep', {
value: (function ()
{
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = '';
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
child.stdin.write("whereis pgrep | awk '{ print $2 }'\nexit\n");
child.waitExit();
return (child.stdout.str.trim());
})()
});
if (this._pgrep != '')
{
this.getProcess = function getProcess(cmd)
{
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("pgrep gnome-session | tr '\\n' '\\t' |" + ' awk -F"\\t" \'{ printf "["; for(i=1;i<NF;++i) { if(i>1) { printf ","; } printf "%d", $i; } printf "]"; }\'');
child.stdin.write('\nexit\n');
child.waitExit();
if (child.stderr.str != '') { throw (child.stderr.str.trim()); }
if (child.stdout.str.trim() == '') { throw (cmd + ' not found'); }
return (JSON.parse(child.stdout.str.trim()));
};
}
this.getProcessEx = function getProcessEx(cmd)
{
var child = require('child_process').execFile('/bin/sh', ['sh']);