Skip to content

Instantly share code, notes, and snippets.

@beatak
Created October 8, 2015 00:38
Show Gist options
  • Save beatak/a22c0f49b9443b03dd3f to your computer and use it in GitHub Desktop.
Save beatak/a22c0f49b9443b03dd3f to your computer and use it in GitHub Desktop.
var wrap_spawn = function (arg_spawn, cb_on_close) {
var child = spawn.apply(null, arg_spawn);
var stdout = [];
var stderr = [];
child.stdout.on('data', function (data) {
stdout.push(data.toString());
});
child.stderr.on('data', function (data) {
stderr.push(data.toString());
});
child.once('close', function (code) {
cb_on_close(code, stdout.join(''), stderr.join(''));
child.stdout.removeAllListeners();
child.stderr.removeAllListeners();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment