lib/childprocess/jruby/process.rb in childprocess-0.1.0 vs lib/childprocess/jruby/process.rb in childprocess-0.1.1

- old
+ new

@@ -1,15 +1,20 @@ require "java" module ChildProcess module JRuby class Process < AbstractProcess + def io + @io ||= JRuby::IO.new + end + def exited? return true if @exit_code assert_started @exit_code = @process.exitValue + true rescue java.lang.IllegalThreadStateException false ensure log(:exit_code => @exit_code) end @@ -24,36 +29,36 @@ end private def launch_process - # background_args! if @detach - pb = java.lang.ProcessBuilder.new(@args) - # not sure why this is necessary env = pb.environment ENV.each { |k,v| env.put(k, v) } @process = pb.start - - # Firefox 3.6 on Snow Leopard has a lot output on stderr, which makes - # the launch act funny if we don't do something to the streams - # Closing the streams solves the problem for now, but on other platforms - # we might need to actually read them. - - @process.getErrorStream.close - @process.getInputStream.close + setup_io end - def background_args! - case ChildProcess.os - when :windows - args = %w[start /wait /b] - @args.unshift(*args) unless @args[0] == start + def setup_io + if @io + redirect @process.getErrorStream, @io.stderr + redirect @process.getInputStream, @io.stdout else - @args.push "&" unless @args.last == "&" + @process.getErrorStream.close + @process.getInputStream.close end + end + + def redirect(input, output) + if output.nil? + input.close + return + end + + output = output.to_outputstream + Thread.new { Redirector.new(input, output).run } end end # Process end # JRuby end # ChildProcess