Class: EnginePack::CommandRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/engine_pack/command_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(io: Open3) ⇒ CommandRunner

Returns a new instance of CommandRunner.



3
4
5
# File 'lib/engine_pack/command_runner.rb', line 3

def initialize(io: Open3)
  @io = io
end

Instance Method Details

#run(cmd, environment_variables = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/engine_pack/command_runner.rb', line 7

def run(cmd, environment_variables = {})
  io.popen3(
    environment_variables,
    "#{cmd} 2>&1"
  ) do |stdin, stdout, _stderr, wait_thread|
    stdin.close_write

    while line = stdout.gets
      puts line
    end

    puts wait_thread.value
  end
end