Sha256: ca4d2203bfeb1b6eb6d025c8b347c3e3b69bfb6cc85ab17299c4c232aedf9246

Contents?: true

Size: 790 Bytes

Versions: 6

Compression:

Stored size: 790 Bytes

Contents

# coding: UTF-8

module Cocaine
  class CommandLine
    class ProcessRunner
      def self.available?
        Process.respond_to?(:spawn)
      end

      def self.supported?
        available? && !OS.java?
      end

      def supported?
        self.class.supported?
      end

      def call(command, env = {}, options = {})
        input, output = IO.pipe
        options[:out] = output
        pid = spawn(env, command, options)
        output.close
        result = input.read
        waitpid(pid)
        input.close
        result
      end

      private

      def spawn(*args)
        Process.spawn(*args)
      end

      def waitpid(pid)
        Process.waitpid(pid)
      rescue Errno::ECHILD
        # In JRuby, waiting on a finished pid raises.
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
solidus_backend-1.0.0.pre3 vendor/bundle/gems/cocaine-0.5.7/lib/cocaine/command_line/runners/process_runner.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/cocaine-0.5.7/lib/cocaine/command_line/runners/process_runner.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/cocaine-0.5.7/lib/cocaine/command_line/runners/process_runner.rb
cocaine-0.5.7 lib/cocaine/command_line/runners/process_runner.rb
cocaine-0.5.6 lib/cocaine/command_line/runners/process_runner.rb
cocaine-0.5.5 lib/cocaine/command_line/runners/process_runner.rb