Skip to content

Instantly share code, notes, and snippets.

@rphillips
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rphillips/92dfdee2e906c36ef595 to your computer and use it in GitHub Desktop.
Save rphillips/92dfdee2e906c36ef595 to your computer and use it in GitHub Desktop.
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