Sha256: 64c19ca8fd2bb080576f6273b3419111557c050eba04337f6aeed7e9c13216ee

Contents?: true

Size: 875 Bytes

Versions: 5

Compression:

Stored size: 875 Bytes

Contents

module Methadone
  module ExecutionStrategy
    # Methadone::ExecutionStrategy for the JVM that uses JVM classes to run the command and get its results.
    class JVM < Base
      def run_command(command)
        process = java.lang.Runtime.get_runtime.exec(command)
        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

5 entries across 5 versions & 1 rubygems

Version Path
methadone-1.0.0.rc5 lib/methadone/execution_strategy/jvm.rb
methadone-1.0.0.rc4 lib/methadone/execution_strategy/jvm.rb
methadone-1.0.0.rc3 lib/methadone/execution_strategy/jvm.rb
methadone-1.0.0.rc2 lib/methadone/execution_strategy/jvm.rb
methadone-1.0.0.rc1 lib/methadone/execution_strategy/jvm.rb