Class: Command
- Inherits:
-
Hash
- Object
- Hash
- Command
- Defined in:
- lib/command.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(command) ⇒ Command
constructor
A new instance of Command.
Constructor Details
#initialize(command) ⇒ Command
Returns a new instance of Command.
2 3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/command.rb', line 2 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 |
Instance Method Details
#execute ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/command.rb', line 16 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 |