Skip to content

Instantly share code, notes, and snippets.

@bidiu
Last active August 11, 2017 16:36
Show Gist options
  • Save bidiu/eca9fc953bc0b96a4e3dbf2d5580b6e2 to your computer and use it in GitHub Desktop.
Save bidiu/eca9fc953bc0b96a4e3dbf2d5580b6e2 to your computer and use it in GitHub Desktop.
const { exec } = require('child_process');
module.exports = function execCmd(cmd, { fromDir = '.' } = {}) {
return new Promise((resolve, reject) => {
exec(`cd ${fromDir} & ${cmd}`, (error, stdout, stderr) => {
if (!error) {
resolve(stdout);
} else {
reject({ error: error, stderr: stderr });
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment