Class: Del::ShellCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/del/shell_command.rb

Overview

Executes shell commands and pipes the results back to the caller.

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ ShellCommand

Returns a new instance of ShellCommand.



7
8
9
# File 'lib/del/shell_command.rb', line 7

def initialize(command)
  @command = Array(command).flatten.join(' ')
end

Instance Method Details

#runObject



11
12
13
14
15
16
17
# File 'lib/del/shell_command.rb', line 11

def run
  Open3.popen3(@command) do |_stdin, stdout, stderr, wait_thr|
    stdout.each_line { |line| yield line }
    stderr.each_line { |line| yield line }
    wait_thr.value.success?
  end
end