I have function below.
function sh(cmd) {
exec(cmd, (err, stdout, stderr) => {
if (err) {
console.log(err);
std_value.flush();
std_value.set("error");
} else {
console.log({stdout, stderr});
std_value.flush();
std_value.set(stdout);
console.log('std_value in ' + std_value.result);
}
});
console.log('std_value out ' + std_value.result);
return std_value.result;
}
I want to sh(cmd)
return output of cmd
. So i am using the following(it is little bit shitty). But exec
is async function, so outer std_value.result
will be the value from last call. Is it normal way to create sh(cmd)
, which wiil return stdout or I should use promises?