Sha256: 395b942af70ad975944b9e00d1c9f2c7fabf15df630fcaf9deb344e6198fe9a7

Contents?: true

Size: 926 Bytes

Versions: 2

Compression:

Stored size: 926 Bytes

Contents

# coding: UTF-8

module Cocaine
  class CommandLine
    class PopenRunner
      def self.supported?
        true
      end

      def supported?
        self.class.supported?
      end

      def call(command, env = {}, options = {})
        with_modified_environment(env) do
          IO.popen(env_command(command), "r", options) do |pipe|
            pipe.read
          end
        end
      end

      private

      def env_command(command)
        windows_command(command) || java_command(command) || default_command(command)
      end

      def windows_command(command)
        if OS.windows?
          command
        end
      end

      def java_command(command)
        if OS.java?
          "env #{command}"
        end
      end

      def default_command(command)
        command
      end

      def with_modified_environment(env, &block)
        ClimateControl.modify(env, &block)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cocaine-0.5.6 lib/cocaine/command_line/runners/popen_runner.rb
cocaine-0.5.5 lib/cocaine/command_line/runners/popen_runner.rb