Class: Blubber::Runner
- Inherits:
-
Object
- Object
- Blubber::Runner
- Defined in:
- lib/blubber/runner.rb
Instance Method Summary collapse
-
#initialize(logger:) ⇒ Runner
constructor
A new instance of Runner.
- #run(cmd) ⇒ Object
Constructor Details
#initialize(logger:) ⇒ Runner
Returns a new instance of Runner.
5 6 7 |
# File 'lib/blubber/runner.rb', line 5 def initialize(logger:) @logger = logger end |
Instance Method Details
#run(cmd) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/blubber/runner.rb', line 9 def run(cmd) # see: http://stackoverflow.com/a/1162850/83386 Open3.popen3(cmd) do |_stdin, stdout, stderr, thread| # read each stream from a new thread { out: stdout, err: stderr }.each do |key, stream| Thread.new do until (line = stream.gets).nil? # yield the block depending on the stream if key == :out logger.info line.strip yield line, nil, thread if block_given? else logger.error line.strip yield nil, line, thread if block_given? end end end end thread.join thread.value.exitstatus end end |