Skip to content

Instantly share code, notes, and snippets.

@othree
Created August 9, 2017 08:50
Show Gist options
  • Save othree/a58da65f1d35ed77ac83e6b3df2830df to your computer and use it in GitHub Desktop.
Save othree/a58da65f1d35ed77ac83e6b3df2830df to your computer and use it in GitHub Desktop.
const spawn = require('child_process').spawn;
// const exec = require('child_process').execSync;
const exec = function (cmd, args) {
return new Promise(function (resolve) {
const execution = spawn(cmd, args);
execution.stdout.on('data', (data) => {
var str = data.toString();
var lines = str.split(/(\r?\n)/g);
for (var i = 0; i < lines.length; i++) {
if (lines[i].trim()) {
console.log(lines[i]);
}
}
});
execution.stderr.on('data', (data) => {
var str = data.toString();
var lines = str.split(/(\r?\n)/g);
for (var i = 0; i < lines.length; i++) {
if (lines[i].trim()) {
console.log('[Error]: ' + lines[i]);
}
}
});
execution.on('close', (code) => {
resolve();
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment