When I execute tasklist on child_process the stdout retuns the processes in Unicode string format which I cannot easily query.
This is my code;
var exec = require('child_process').exec;
...
exec('tasklist', function(err, stdout, stderr) {
...
});
This is a part of stdout;
\r\nImage Name PID Session Name Session# Mem Usage\r\n========================= ======== ================ =========== ============\r\nSystem Idle Process 0 Services 0 8 K\r\nSystem 4 Services 0 3,900 K\r\nRegistry 148 Services 0 57,232 K\r\nsmss.exe 636 Services 0 444 K\r\ncsrss.exe 820 Services 0 3,604 K\r\nwininit.exe 716 Services 0 2,824 K\r\nservices.exe 8 Services 0 9,180 K\r\nlsass.exe...
How can I get the stdout in JSON format?
I tried several methods to convert from Unicode to JSON but could not find a simple way.
parse the string by splitting it into lines, then further splitting each line into an array of values. You can then use this array to construct a JSON object
example: