lib/systemu.rb in systemu-2.6.4 vs lib/systemu.rb in systemu-2.6.5
- old
+ new
@@ -12,11 +12,11 @@
class SystemUniversal
#
# constants
#
- SystemUniversal::VERSION = '2.6.4' unless SystemUniversal.send(:const_defined?, :VERSION)
+ SystemUniversal::VERSION = '2.6.5' unless SystemUniversal.send(:const_defined?, :VERSION)
def SystemUniversal.version() SystemUniversal::VERSION end
def version() SystemUniversal::VERSION end
def SystemUniversal.description
"universal capture of stdout and stderr and handling of child process pid for windows, *nix, etc."
end
@@ -26,21 +26,26 @@
@host = Socket.gethostname
@ppid = Process.ppid
@pid = Process.pid
@turd = ENV['SYSTEMU_TURD']
+ @ruby = nil
- c = begin; ::RbConfig::CONFIG; rescue NameError; ::Config::CONFIG; end
- ruby = File.join(c['bindir'], c['ruby_install_name']) << c['EXEEXT']
- @ruby = if system('%s -e 42' % ruby)
- ruby
- else
- system('%s -e 42' % 'ruby') ? 'ruby' : warn('no ruby in PATH/CONFIG')
+ def self.ruby
+ return @ruby if @ruby
+
+ c = begin; ::RbConfig::CONFIG; rescue NameError; ::Config::CONFIG; end
+ ruby = File.join(c['bindir'], c['ruby_install_name']) << c['EXEEXT']
+ @ruby = if system('%s -e 42' % ruby)
+ ruby
+ else
+ system('%s -e 42' % 'ruby') ? 'ruby' : warn('no ruby in PATH/CONFIG')
+ end
end
class << SystemUniversal
- %w( host ppid pid ruby turd ).each{|a| attr_accessor a}
+ %w( host ppid pid turd ).each{|a| attr_accessor a}
def quote(*words)
words.map{|word| word.inspect}.join(' ')
end
end
@@ -177,11 +182,11 @@
<<-program
# encoding: utf-8
PIPE = STDOUT.dup
begin
- config = Marshal.load(IO.read('#{ config }'))
+ config = Marshal.load(IO.read('#{ config }',:mode=>"rb"))
argv = config['argv']
env = config['env']
cwd = config['cwd']
stdin = config['stdin']
@@ -284,13 +289,14 @@
stdout, stderr = [process.input_stream, process.error_stream].map do |stream|
StreamReader.new(stream)
end
- exit_code = process.wait_for
field = process.get_class.get_declared_field("pid")
field.set_accessible(true)
pid = field.get(process)
+ thread = new_thread pid, @block if @block
+ exit_code = process.wait_for
[
RubyProcess::RubyStatus.new_process_status(JRuby.runtime, exit_code, pid),
stdout.join,
stderr.join
]