Sha256: 0d18c4c1241171fe005c91d91c52bfb26abe6e78f83192c6d4702631bda71dc5

Contents?: true

Size: 1.31 KB

Versions: 18

Compression:

Stored size: 1.31 KB

Contents

require 'open3'

require 'fedux_org/stdlib/environment'
require 'fedux_org/stdlib/command/command_result'

module FeduxOrg
  module Stdlib
    module Command
      include Environment

      # Execute command
      #
      # @param [String] cmd
      #   the command 
      #
      # @param [Hash] options
      #   the options for command execution
      #
      # @option options [Hash] env ({])
      #   the environment variables for the command ('VAR' => 'CONTENT')
      #
      # @option options [String] stdin (nil)
      #   the string for stdin of the command
      #
      # @option options [TrueClass,FalseClass] binmode (false)
      #   should the stdin be read a binary or not
      #
      # @return [CommandResult]
      #   the result of the command execution
      #
      # @return [CommandResult]
      #   the result of the command execution
      def run_command(cmd,options={})
        opts = {
          env: nil,
          stdin: nil,
          binmode: false,
        }.merge options

        env = opts[:env] || ENV.to_hash
        stdin = opts[:stdin] 
        binmode = opts[:binmode]

        result = CommandResult.new
        result.stdout, result.stderr, result.status = Open3.capture3(env, cmd, stdin_data: stdin, chdir: working_directory, binmode: binmode)

        result
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.0.22 lib/fedux_org/stdlib/command.rb
fedux_org-stdlib-0.0.21 lib/fedux_org/stdlib/command.rb
fedux_org-stdlib-0.0.20 lib/fedux_org/stdlib/command.rb
fedux_org-stdlib-0.0.19 lib/fedux_org/stdlib/command.rb
fedux_org-stdlib-0.0.17 lib/fedux_org/stdlib/command.rb
fedux_org-stdlib-0.0.16 lib/fedux_org/stdlib/command.rb
fedux_org-stdlib-0.0.14 lib/fedux_org/stdlib/command.rb
fedux_org-stdlib-0.0.13 lib/fedux_org/stdlib/command.rb
fedux_org-stdlib-0.0.12 lib/fedux_org/stdlib/command.rb
fedux_org-stdlib-0.0.11 lib/fedux_org/stdlib/command.rb
fedux_org-stdlib-0.0.10 lib/fedux_org/stdlib/command.rb
fedux_org-stdlib-0.0.9 lib/fedux_org/stdlib/command.rb
fedux_org-stdlib-0.0.8 lib/fedux_org/stdlib/command.rb
fedux_org-stdlib-0.0.6 lib/fedux_org/stdlib/command.rb
fedux_org-stdlib-0.0.5 lib/fedux_org/stdlib/command.rb
fedux_org-stdlib-0.0.4 lib/fedux_org/stdlib/command.rb
fedux_org-stdlib-0.0.3 lib/fedux_org/stdlib/command.rb
fedux_org-stdlib-0.0.2 lib/fedux_org/stdlib/command.rb