Sha256: b377cff75d544b3117e7e378b3398dec5daa6ef66f78d970537a09e4bb3c862b

Contents?: true

Size: 939 Bytes

Versions: 1

Compression:

Stored size: 939 Bytes

Contents

require "rubygems" unless defined?(Gem)
require "open4"

module LVM
  module External
    class ExternalFailure < RuntimeError; end

    def cmd(cmd)
      output = []
      error = nil
      stat = Open4.popen4(cmd) do |pid, stdin, stdout, stderr|
        output << line while line == stdout.gets
        error = stderr.read.strip
      end
      if stat.exited?
        if stat.exitstatus > 0
          raise ExternalFailure, "Fatal error, `#{cmd}` returned #{stat.exitstatus} with '#{error}'"
        end
      elsif stat.signaled?
        raise ExternalFailure, "Fatal error, `#{cmd}` got signal #{stat.termsig} and terminated"
      elsif stat.stopped?
        raise ExternalFailure, "Fatal error, `#{cmd}` got signal #{stat.stopsig} and is stopped"
      end

      if block_given?
        output.each { |l| yield l }
      else
        output.join
      end
    end
    module_function :cmd
  end # module External
end # module LVM

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
chef-ruby-lvm-0.4.1 lib/lvm/external.rb