Sha256: 3dd1e5df923313a3c8d8dfdabdcc3c968ffa4d7a5c6af3168d8eae0160ec0dc3

Contents?: true

Size: 1.04 KB

Versions: 14

Compression:

Stored size: 1.04 KB

Contents

require 'open3'

module Wixgem

class Command < Hash
  def initialize(cmd, options=nil)
   self[:output] = ''
   self[:error] = ''
   self[:exit_code] = ''
   self[:ignore_exit_code] = false
   self[:debug] = false
   self[:quiet] = false

   self[:command]=cmd
   options.each { |key, value| self[key] = value} unless(options.nil?)
  end
  
  def execute
    begin
	  puts self[:command] unless(self[:quiet])
      self[:output],self[:error], self[:exit_code] = Open3.capture3(self[:command])
      self[:exit_code]=self[:exit_code].to_i
	  
	  if(self[:debug])
		puts "command: #{self[:command]}" if(self[:quiet])
	    puts "output: #{self[:output]}"
	    puts "error: #{self[:error]}"
	    puts "exit_code: #{self[:exit_code]}"
	  end
	rescue Exception => e
	  self[:error] = "Exception: " + e.to_s
	  self[:exit_code]=1
	end
	
	if((self[:exit_code] != 0) && !self[:ignore_exit_code])
	  exception_text = self[:error]
	  exception_text = self[:output] if(self[:error].empty?)
	  raise exception_text 
	end
  end
end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
wixgem-0.64.0 lib/command.rb
wixgem-0.63.0 lib/command.rb
wixgem-0.62.0 lib/command.rb
wixgem-0.59.0 lib/command.rb
wixgem-0.58.0 lib/command.rb
wixgem-0.57.0 lib/command.rb
wixgem-0.56.0 lib/command.rb
wixgem-0.55.0 lib/command.rb
wixgem-0.54.0 lib/command.rb
wixgem-0.53.0 lib/command.rb
wixgem-0.52.0 lib/command.rb
wixgem-0.51.0 lib/command.rb
wixgem-0.50.0 lib/command.rb
wixgem-0.49.0 lib/command.rb