class Command < Hash def initialize command 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 def execute Logger.start_command self #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]=$? #if $? != 0 # puts self[:output] # raise Color.yellow + "`" + Color.green + self[:input] + Color.yellow + "`" + Color.clear + # " has exit code " + $?.to_s + " " + out #else # puts " " + timer.elapsed_str #end end Logger.end_command self end end