-
-
Save othree/a58da65f1d35ed77ac83e6b3df2830df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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