Let's import child_process
's exec
function as a promise:
const util = require("util")
const exec = util.promisify(require("child_process").exec)
Then we run exec
with a current working directory argument, if we want, and then wait upon the result of such:
exec("ls -l", { cwd: "/home/bees/and/bees/" })
.then((stdout, stderr) => {
console.log("completed program", stdout, stderr)
})
.catch(e => {
console.log("failed to start program", e)
})