Sha256: eb736ca9614842ff15891ae247488acbd79f5c801ca251314addae21cf041b8a

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

class Command < Hash
	def initialize command

		if(command.kind_of?(String))
		  self[:input] = command
		  self[:timeout] = 0
		  self[:directory] = ''
		  self[:exit_code] = 0
		  self[:output] = ''
		  self[:error] = ''
		  self[:machine_name] = ''
		  self[:user_name] = ''
		  self[:start_time] = nil
		  self[:end_time] = nil
        end

        if(command.kind_of?(Hash))
        	command.each{|k,v|
        		self[k.to_sym]=v
        	}
        end
	end

	def execute

		Logger.start_command self

		pwd=Dir.pwd
		Dir.chdir(self[:directory]) if(self.has_key?(:directory) && File.exists?(self[:directory]))
		#print " " + Color.green + self[:input] + Color.clear

		self[:start_time]=Time.now
		timer=Timer.new
		if self[:input].include?('<%') && self[:input].include?('%>')
		  ruby = self[:input].gsub("<%","").gsub("%>","")
		  self[:output]=eval(ruby)
		  #puts " " + timer.elapsed_str
		  self[:elapsed] = timer.elapsed_str
		  self[:end_time] = Time.now
		else
			self[:output] = `#{self[:input]}`
			self[:elapsed] = timer.elapsed_str
			self[:end_time] = Time.now
			self[:exit_code]=$?.to_i
		end

        Dir.chdir(pwd) if pwd != Dir.pwd
		Logger.end_command self
	end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dev_tasks-1.0.12 lib/command.rb
dev_tasks-1.0.11 lib/command.rb