Module: Gorillib::System::Runner

Extended by:
Runner
Included in:
Runner
Defined in:
lib/gorillib/system/runner.rb

Instance Method Summary collapse

Instance Method Details

#run(args, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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