Class: EmbeddedJs::Adaptors::CommandRunner

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

Instance Method Summary collapse

Constructor Details

#initialize(io: Open3) ⇒ CommandRunner

Returns a new instance of CommandRunner.



8
9
10
# File 'lib/embedded_js/adaptors/command_runner.rb', line 8

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

Instance Method Details

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



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/embedded_js/adaptors/command_runner.rb', line 12

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