Skip to content

Instantly share code, notes, and snippets.

@excenter
Created June 20, 2018 20:58
Show Gist options
  • Save excenter/4362c01871f22334af2e296f64a90812 to your computer and use it in GitHub Desktop.
Save excenter/4362c01871f22334af2e296f64a90812 to your computer and use it in GitHub Desktop.
a javascript function that takes a string and runs it as bash, returning the output to the std pipes.
function bashRun(command){
var exec = require('child_process').exec;
console.log(command);
var child = exec(command);
child.stdout.on('data', function(data) {
console.log('stdout: ' + data);
});
child.stderr.on('data', function(data) {
console.log('stderr: ' + data);
});
child.on('close', function(code) {
console.log('closing code: ' + code);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment