Class: Ikaros::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/ikaros/command.rb

Instance Method Summary collapse

Constructor Details

#initialize(command, options = {}) ⇒ Command

Returns a new instance of Command.



5
6
7
8
# File 'lib/ikaros/command.rb', line 5

def initialize(command, options={})
  @command = command
  @options = options
end

Instance Method Details

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ikaros/command.rb', line 10

def run
  logger.debug @command
  result = ''
  Open3.popen3(@command) do |stdin, stdout, stderr, wait_thr|
    while line = stdout.gets
      result = "#{result}#{line}"
      logger.debug line
      logger.info line if output?
    end
    unless wait_thr.value.success?
      raise Error::CommandError.new stderr.gets(nil)
    end
  end
  result.chomp
end