Class: Wip::CommandRunner
- Inherits:
-
Object
- Object
- Wip::CommandRunner
- Defined in:
- lib/wip/command_runner.rb
Overview
Executes a built command, pumping its I/O and returning the exit status.
Instance Method Summary collapse
-
#initialize(stdin: $stdin, stdout: $stdout, stderr: $stderr, interpreter: ErrorInterpreter.new) ⇒ CommandRunner
constructor
A new instance of CommandRunner.
- #run(command, env: {}) ⇒ Object
Constructor Details
#initialize(stdin: $stdin, stdout: $stdout, stderr: $stderr, interpreter: ErrorInterpreter.new) ⇒ CommandRunner
Returns a new instance of CommandRunner.
9 10 11 12 13 14 |
# File 'lib/wip/command_runner.rb', line 9 def initialize(stdin: $stdin, stdout: $stdout, stderr: $stderr, interpreter: ErrorInterpreter.new) @stdin = stdin @stdout = stdout @stderr = stderr @interpreter = interpreter end |
Instance Method Details
#run(command, env: {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/wip/command_runner.rb', line 16 def run(command, env: {}) @stderr.puts "+ #{Shellwords.join(command)}" if ENV['WIP_DEBUG'] captured = +'' status = nil Open3.popen3(env, *command) do |input, output, error, wait| input.close threads = [pump(output, @stdout, captured), pump(error, @stderr, captured)] threads.each(&:join) status = wait.value end hint = @interpreter.interpret(captured) @stderr.puts("\n#{hint}") if !status.success? && hint status.exitstatus rescue Errno::ENOENT => e @stderr.puts e. 127 end |