# CBlackburn Command class # Wraps arbitrary command lines for execution # within Ruby programs # # Author: Chris Blackburn(cblackburn@cbciweb.com) # Copyright: (c) 2006 Chris Blackburn # License: GPL: http://www.gnu.org/copyleft/gpl.html # Date: December 22, 2006 # $Revision:$ # class CbCommand attr_reader :output attr_reader :command_line attr_reader :exec_time attr_reader :success def initialize(command_line, working_directory=nil) @command_line = command_line @working_directory = working_directory @output = nil end def run? run return @success end #Runs the command. def run prev_dir = Dir.pwd time_begin = Time.new time_end = nil begin Dir.chdir(@working_directory) if @working_directory @cmd = IO.popen("#{@command_line} 2>&1") time_end = Time.new @output = @cmd.readlines @success = true @exec_time = time_end.to_f - time_begin.to_f return @success rescue SystemCallError @success = false return false ensure Dir.chdir(prev_dir) end end end