I would like make this function return the result of the exec command in a var. How would I go about doing this?
// System Serial Number
function systemSerialNumber(response) {
console.log("Request handler 'systemSerialNumber' was called.");
exec("dmidecode -t 1 | grep 'Serial Number:' | cut -d: -f2 | sed -e 's/^[ \t]*//g'", function (error, stdout, stderr) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write(stdout);
response.end();
});
}
From http://nodejs.org/docs/v0.3.1/api/all.html#child_process.exec describes how to get the output of a command asynchronously. But it sounds like you want to get the results synchronously so you can return them, in which case, you're probably more interested in this SO question: node.js execute system command synchronously
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With