Sha256: 6ee1bccc0ba72ef94216ee9356f76b0d23da3d281d3a253e0e7915541ca2a789

Contents?: true

Size: 1.21 KB

Versions: 10

Compression:

Stored size: 1.21 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

10 entries across 10 versions & 1 rubygems

Version Path
dev_tasks-1.0.22 lib/command.rb
dev_tasks-1.0.21 lib/command.rb
dev_tasks-1.0.20 lib/command.rb
dev_tasks-1.0.19 lib/command.rb
dev_tasks-1.0.18 lib/command.rb
dev_tasks-1.0.17 lib/command.rb
dev_tasks-1.0.16 lib/command.rb
dev_tasks-1.0.15 lib/command.rb
dev_tasks-1.0.14 lib/command.rb
dev_tasks-1.0.13 lib/command.rb