Sha256: 3818d7410891ceefca8ffcab08153efb6ec0bdbe883e452fffa45149874a0d7e

Contents?: true

Size: 1.31 KB

Versions: 5

Compression:

Stored size: 1.31 KB

Contents

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

      def stop(timeout = nil)
        assert_started

        @process.destroy
        @process.waitFor # no way to actually use the timeout here..

        @exit_code = @process.exitValue
      end

      private

      def launch_process
        pb = java.lang.ProcessBuilder.new(@args)

        env = pb.environment
        ENV.each { |k,v| env.put(k, v) }

        @process = pb.start
        setup_io
      end

      def setup_io
        if @io
          redirect @process.getErrorStream, @io.stderr
          redirect @process.getInputStream, @io.stdout
        else
          @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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
childprocess-0.1.5 lib/childprocess/jruby/process.rb
childprocess-0.1.4 lib/childprocess/jruby/process.rb
childprocess-0.1.3 lib/childprocess/jruby/process.rb
childprocess-0.1.2 lib/childprocess/jruby/process.rb
childprocess-0.1.1 lib/childprocess/jruby/process.rb