module Gorillib::System::Runner

Public Instance Methods

run(args, options={}) click to toggle source
# File lib/gorillib/system/runner.rb, line 11
def run(args, options={})
  options = options.reverse_merge(mirror_io: false)
  process = ChildProcess.build(*args)
  out = Tempfile.new('gorillib-runner-out')
  err = Tempfile.new('gorillib-runner-err')
  process.io.stdout = out
  process.io.stderr = err
  process.start
  process.wait
  begin 
    out.rewind ; err.rewind
    res = [out.read, err.read, process.exit_code]
    if options[:mirror_io]
      $stdout.write res[0]
      $stderr.write res[1]
    end
  ensure
    out.close ; err.close
    out.unlink ; err.unlink
  end
  res
end