I'm new to Node and stumbling on some of the nonblocking elements of it. I'm trying to create a object and have one of the elements of it being a function that returns the stdout of a child_process.exec, like so:
var exec = require('child_process').exec;
var myObj = {};
myObj.list = function(){
var result;
exec("ls -al", function (error, stdout, stderr) {
result = stdout;
});
return result;
}
console.log('Ta da : '+myObj.list);
I figure that myObj.list is returning result before it is set as stdout, but I can't figure out how to make it wait or do a callback for it. Thanks for your help!