Sha256: d72fb139cab45c18bb7640bef2c9c6ce102f1081aa8af295cd5ab812dadcbbdc

Contents?: true

Size: 843 Bytes

Versions: 1

Compression:

Stored size: 843 Bytes

Contents

# coding: UTF-8

module Cocaine
  class CommandLine
    class PosixRunner
      def self.available?
        require 'posix/spawn'
        true
      rescue LoadError
        false
      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 = ""
        while partial_result = input.read(8192)
          result << partial_result
        end
        waitpid(pid)
        input.close
        result
      end

      private

      def spawn(*args)
        POSIX::Spawn.spawn(*args)
      end

      def waitpid(pid)
        Process.waitpid(pid)
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cocaine-0.5.5 lib/cocaine/command_line/runners/posix_runner.rb