Skip to content

Instantly share code, notes, and snippets.

@fideloper
Created January 4, 2016 20:41
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save fideloper/b465064629689af579f3 to your computer and use it in GitHub Desktop.
Execute a shell script
// Import fs (filesystem)
var chmodSync = require('fs').chmodSync;
// Import execFile, to run our bash script
var execFile = require('child_process').execFile;
chmodSync('./build.sh', 0755);
var execOptions = {
maxBuffer: 1024 * 1024 * 5 // Increase max buffer to 5mb
};
execFile('./somethiung.sh', ['-b foo', '-r bar'] , execOptions, function(error, stdout, stderr) {
if(error)
{
console.error('Error: '+error.message);
}
// Log success in some manner
console.log( 'exec complete', stdout, stderr, error);
});
@slayerlab
Copy link

Thanks for the PoC. I suppose an enhancement at line #12 would be:

if (error || stderr) {
  console.error('Error: '+ (error.message || stderr));
  return;
}
...

Because the stderr is ramble, without any kind of [error] handling on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment