-
-
Save rphillips/92dfdee2e906c36ef595 to your computer and use it in GitHub Desktop.
This file contains 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
local misc = require('/base/util/misc') | |
local async = require('async') | |
local childProcess = require('childprocess') | |
local function execFileToBuffers(command, args, options, callback) | |
local child, stdout, stderr, exitCode | |
stdout = {} | |
stderr = {} | |
callback = misc.fireOnce(callback) | |
child = childProcess.spawn(command, args, options) | |
child.stdout:on('data', function (chunk) | |
table.insert(stdout, chunk) | |
end) | |
child.stderr:on('data', function (chunk) | |
table.insert(stderr, chunk) | |
end) | |
async.parallel({ | |
function(callback) | |
child.stdout:on('end', callback) | |
end, | |
function(callback) | |
child.stderr:on('end', callback) | |
end, | |
function(callback) | |
local onExit | |
function onExit(code) | |
exitCode = code | |
callback() | |
end | |
child:on('exit', onExit) | |
end | |
}, function(err) | |
callback(err, exitCode, table.concat(stdout, ""), table.concat(stderr, "")) | |
end) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment