lib/rbbt/util/cmd.rb in rbbt-util-5.20.22 vs lib/rbbt/util/cmd.rb in rbbt-util-5.20.23
- old
+ new
@@ -1,84 +1,10 @@
require 'rbbt/util/log'
require 'stringio'
module CMD
- #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
- # io.cmd = cmd
- # io.in = sin
- # io.out = out
- # io.err = err
- # io.post = post
- # io.log = log
-
- # io.class.send(:alias_method, :original_close, :close)
- # io.class.send(:alias_method, :original_read, :read)
- # io
- # end
-
- # def wait_and_status
- # if @pid
- # begin
- # Process.waitpid(@pid)
- # rescue
- # end
-
- # Log.debug{"Process #{ cmd } succeded" if $? and $?.success? and log}
-
- # if $? and not $?.success?
- # Log.debug{"Raising exception" if log}
- # exception = ProcessFailed.new "Command [#{@pid}] '#{@cmd}' failed with error status #{$?.exitstatus}"
- # begin
- # original_close
- # ensure
- # raise exception
- # end
- # end
- # end
- # end
-
- # def close
- # self.original_read unless self.closed? or self.eof?
-
- # wait_and_status
-
- # @post.call if @post
-
- # original_close unless self.closed?
- # end
-
- # def force_close
- # if @pid
- # Log.debug{"Forcing close by killing '#{@pid}'" if log}
- # begin
- # Process.kill("KILL", @pid)
- # Process.waitpid(@pid)
- # rescue
- # Log.low{"Exception in forcing close of command [#{ @pid }, #{cmd}]: #{$!.message}"}
- # end
- # end
-
- # @post.call if @post
-
- # original_close unless self.closed?
- # end
-
- # def read(*args)
- # data = original_read(*args) unless self.closed? #or self.eof?
-
- # self.close if not self.closed? and self.eof?
-
- # data #|| ""
- # end
- #end
-
-
def self.process_cmd_options(options = {})
string = ""
options.each do |option, value|
case
when value.nil? || FalseClass === value
@@ -199,11 +125,11 @@
end
serr.close
end
#SmartIO.tie sout, pid, cmd, post, in_content, sin, serr
- ConcurrentStream.setup sout, :pids => [pid], :autojoin => true, :no_fail => no_fail unless no_wait
+ ConcurrentStream.setup sout, :pids => [pid], :autojoin => no_wait, :no_fail => no_fail
sout
else
err = ""
Thread.new do
@@ -211,10 +137,10 @@
err << serr.gets if Integer === stderr
end
serr.close
end
- ConcurrentStream.setup sout, :pids => [pid], :autojoin => true, :no_fail => no_fail
+ ConcurrentStream.setup sout, :pids => [pid], :autojoin => no_wait, :no_fail => no_fail
out = StringIO.new sout.read
sout.close unless sout.closed?
Process.waitpid pid