# File lib/aruba/spawn_process.rb, line 10 def initialize(cmd, exit_timeout, io_wait) @exit_timeout = exit_timeout @io_wait = io_wait @cmd = cmd @process = nil @exit_code = nil end
# File lib/aruba/spawn_process.rb, line 39 def output stdout + stderr end
# File lib/aruba/spawn_process.rb, line 57 def read_stdout wait_for_io do @process.io.stdout.flush open(@out.path).read end end
# File lib/aruba/spawn_process.rb, line 19 def run!(&block) @process = ChildProcess.build(*shellwords(@cmd)) @out = Tempfile.new("aruba-out") @err = Tempfile.new("aruba-err") @process.io.stdout = @out @process.io.stderr = @err @process.duplex = true @exit_code = nil begin @process.start rescue ChildProcess::LaunchError => e raise LaunchError.new(e.message) end yield self if block_given? end
# File lib/aruba/spawn_process.rb, line 50 def stderr wait_for_io do @err.rewind @err.read end end
# File lib/aruba/spawn_process.rb, line 35 def stdin @process.io.stdin end
# File lib/aruba/spawn_process.rb, line 43 def stdout wait_for_io do @out.rewind @out.read end end
# File lib/aruba/spawn_process.rb, line 64 def stop(reader) return @exit_code unless @process unless @process.exited? @process.poll_for_exit(@exit_timeout) end reader.stdout stdout reader.stderr stderr @exit_code = @process.exit_code @process = nil @exit_code end
# File lib/aruba/spawn_process.rb, line 76 def terminate if @process stdout && stderr # flush output @process.stop stdout && stderr # flush output end end
# File lib/aruba/spawn_process.rb, line 86 def wait_for_io(&block) sleep @io_wait if @process yield end