lib/rbbt/util/cmd.rb in rbbt-util-5.12.2 vs lib/rbbt/util/cmd.rb in rbbt-util-5.12.3

- old
+ new

@@ -1,12 +1,10 @@ require 'rbbt/util/log' require 'stringio' module CMD - class CMDError < StandardError; end - module SmartIO attr_accessor :pid, :cmd, :post, :in, :out, :err, :log def self.tie(io, pid = nil, cmd = "", post = nil, sin = nil, out = nil, err = nil, log = true) io.extend SmartIO io.pid = pid @@ -31,11 +29,11 @@ Log.debug{"Process #{ cmd } succeded" if $? and $?.success? and log} if $? and not $?.success? Log.debug{"Raising exception" if log} - exception = CMDError.new "Command [#{@pid}] '#{@cmd}' failed with error status #{$?.exitstatus}" + exception = ProcessFailed.new "Command [#{@pid}] '#{@cmd}' failed with error status #{$?.exitstatus}" begin original_close ensure raise exception end @@ -158,13 +156,13 @@ exec(ENV, cmd) exit(-1) rescue Exception - Log.debug{ "CMDError: #{$!.message}" } if log + Log.debug{ "ProcessFailed: #{$!.message}" } if log Log.debug{ "Backtrace: \n" + $!.backtrace * "\n" } if log - raise CMDError, $!.message + raise ProcessFailed, $!.message end } sin.first.close sout.last.close @@ -205,11 +203,12 @@ end serr.close Thread.exit end - SmartIO.tie sout, pid, cmd, post, in_content, sin, serr + #SmartIO.tie sout, pid, cmd, post, in_content, sin, serr + ConcurrentStream.setup sout, :pids => [pid], :autojoin => true sout else err = "" Thread.new do @@ -220,15 +219,15 @@ Thread.exit end out = StringIO.new sout.read sout.close unless sout.closed? - SmartIO.tie out, pid, cmd, post, in_content, sin, serr + #SmartIO.tie out, pid, cmd, post, in_content, sin, serr Process.waitpid pid if not $?.success? - exception = CMDError.new "Command [#{pid}] #{cmd} failed with error status #{$?.exitstatus}.\n#{err}" + exception = ProcessFailed.new "Command [#{pid}] #{cmd} failed with error status #{$?.exitstatus}.\n#{err}" raise exception else Log.log err, stderr if Integer === stderr and log end