Sha256: 8f590b3421bdf2835921c8e8500deab5ca2efa4a6958ca1d5974a0f444ce7b95
Contents?: true
Size: 1.66 KB
Versions: 11
Compression:
Stored size: 1.66 KB
Contents
puts_debug "read " + __FILE__.foreground(:green) require 'tmpdir' module Dev class SystemCall attr_accessor :output,:error,:status,:command,:start_time,:end_time,:timed_out def initialize(cmd); execute(cmd); end def elapsed; @end_time-@start_time; end def execute(cmd) @command=cmd @start_time=Time.now filename=Dir.tmpdir + "/" + (0...8).map{65.+(rand(25)).chr}.join begin system("#{@command} >#{filename}.out 2>#{filename}.err") File.open("#{filename}.out",'r') {|f| @output = f.read f.close } File.open("#{filename}.err",'r') {|f| @error = f.read f.close } @status=$?.exitstatus @end_time=Time.now rescue puts "error executing ruby code" ensure begin File.delete("#{filename}.out") if File.exists?("#{filename}.out") File.delete("#{filename}.err") if File.exists?("#{filename}.err") rescue puts "temp directory file was not cleaned up." end end end def puts_summary if(@status != 0) puts " [".foreground(:cyan) + "X".foreground(:red).bright + "]".foreground(:cyan) + " system(\"" + @command.foreground(:green) + "\") has exit status of " + @status.to_s puts @output warn @error throw "exit status was " + @status.to_s else elapsed_str="[" + "%.0f" %(elapsed) + "s]" puts " [".foreground(:cyan) + "+".foreground(:green) + "]".foreground(:cyan) + " system(\"" + @command.foreground(:green) + "\") " + elapsed_str.foreground(:cyan) end end end # class SystemCall end # module Dev
Version data entries
11 entries across 11 versions & 1 rubygems