Hello I'm creating a plugin which uses some command line commands in order to get the process memory and cpu usage how ever altho the command works in terminal it does not when running with node.
Furthermore when running with node the findstr part doesnt work at all, and because of that I get all the process list from stdout. Normally I should have had one 1 line:
Here is the source:
var spawn = require('child_process').spawn;
var readline = require('readline');
function Pstats() {
this.os = /^win/.test(process.platform) === true ? 'win' : 'nix';
this.win_cmd_arr = ['/C', 'wmic', 'path', 'Win32_PerfFormattedData_PerfProc_Process', 'get', 'IDProcess,WorkingSet,PercentProcessorTime', '|', 'findstr', '/R', '"^' + process.pid + '"'];
};
// this for example will list all processes with starting pid of 4
// wmic path Win32_PerfFormattedData_PerfProc_Process get IDProcess,WorkingSet,PercentProcessorTime | findstr /R "^4"
Object.defineProperties(Pstats.prototype, {
constructor: Pstats,
usage: {
enumerable: false,
value: function(callback) {
if (this.os === 'win') {
var proc = spawn('cmd.exe', this.win_cmd_arr);
proc.stdout.on('data', function(data) {
console.log(data.toString());
});
// readline.createInterface({
// input: proc.stdout,
// terminal: false
// }).on('line', function(line) {
// console.log(line);
// });
// readline.createInterface({
// input: proc.stderr,
// terminal: false
// }).on('line', function(line) {
// console.error(line);
// });
} else {
throw new TypeError('unsupported operatin system');
}
}
}
});
exports = module.exports = (function() {
return new Pstats();
})();