Sha256: 00d1f505ac91a933958c8b1a432fa04e7cbf84699f4e71b8186106f6a8c1c459

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

module OptparsePlus
  module ExecutionStrategy
    # <b>OptparsePlus Internal - treat as private</b>
    #
    # OptparsePlus::ExecutionStrategy for the JVM that uses JVM classes to run the command and get its results.
    class JVM < Base
      def run_command(command)
        process = case command
                  when String then
                    java.lang.Runtime.get_runtime.exec(command)
                  else
                    java.lang.Runtime.get_runtime.exec(*command)
                  end
        process.get_output_stream.close
        stdout = input_stream_to_string(process.get_input_stream)
        stderr = input_stream_to_string(process.get_error_stream)
        exitstatus = process.wait_for
        [stdout.chomp,stderr.chomp,OpenStruct.new(:exitstatus => exitstatus)]
      end

      def exception_meaning_command_not_found
        NativeException
      end

    private
      def input_stream_to_string(is)
        ''.tap do |string|
          ch = is.read
          while ch != -1
            string << ch
            ch = is.read
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
optparse-plus-3.0.1 lib/optparse_plus/execution_strategy/jvm.rb
optparse-plus-3.0.0 lib/optparse_plus/execution_strategy/jvm.rb