module Rabbit::SystemRunner
Public Instance Methods
run(cmd, *args, progress: nil) { |$!| ... }
click to toggle source
# File lib/rabbit/utils.rb, line 355 def run(cmd, *args, progress: nil) begin IO.pipe do |input, output| pid = spawn(cmd, *args, out: output) output.close begin loop do readables, = IO.select([input], nil, nil, 0.1) if readables readable = readables[0] begin $stdout.print(readable.read_nonblock(4096)) rescue EOFError break else break if readable.eof? end else progress.call if progress end end true ensure Process.waitpid(pid) end end rescue SystemCallError yield($!) if block_given? false end end