class System

Public Class Methods

call(command) click to toggle source
# File vendor/system.rb, line 7
def call(command)
  command = command.to_s
  result = Struct.new(:stdout,
                      :stderr,
                      :exit_status).new([], [], 0)

  Open3.popen3(command) do |stdin, stdout, stderr, thread|
    thread.join
    result.exit_status = thread.value
    
    until (line = stdout.gets).nil? do
      result.stdout << line
    end

    until (line = stderr.gets).nil? do
      result.stderr << line
    end

    thread.join
    result.exit_status = thread.value
  end

  result
end
call!(command) click to toggle source
# File vendor/system.rb, line 32
def call!(command)
  call(command).tap do |response|
    raise(System::CommandError,
          "Error running \"#{command.to_s}\" (Exited with status code #{response.exit_status}) \n" \
        + "STDERR: \n#{response.stderr}") if response.exit_status != 0
  end
end