I've seen a similar question once, but I can't for the life of me figure out why this isn't working. I have a pretty simple program below that should wrap the exec function and return the result. However all it returns is undefined. Here's the function:
var exec = require('child_process').execSync;
quickexec = function(command) {
exec(command, function(error, stdout, stderr) {
if(error) {
return error;
} else {
return stdout;
}
});
};
I call it like this console.log(quickexec('echo -n $USER'));
and I get undefined everytime. However if I change the return in my function to a console.log it works. I thought that it was an async problem which is why I started using execSync
, but it didn't change anything.