Sha256: b3b5add8ae708a3d2be048f69e7e8fe0c5808ec28c243aa9230cc95200e1d7ac

Contents?: true

Size: 1.48 KB

Versions: 64

Compression:

Stored size: 1.48 KB

Contents

# encoding: utf-8
require 'fedux_org_stdlib/require_files'
require_library %w{ open3 }

require 'fedux_org_stdlib/environment'
require 'fedux_org_stdlib/command/command_result'

module FeduxOrgStdlib
  module Command
    module RunCommand
      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,
          working_directory: Dir.getwd,
        }.merge options

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

        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

64 entries across 64 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.7.21 lib/fedux_org_stdlib/command/run_command.rb
fedux_org-stdlib-0.7.20 lib/fedux_org_stdlib/command/run_command.rb
fedux_org-stdlib-0.7.19 lib/fedux_org_stdlib/command/run_command.rb
fedux_org-stdlib-0.7.18 lib/fedux_org_stdlib/command/run_command.rb
fedux_org-stdlib-0.7.17 lib/fedux_org_stdlib/command/run_command.rb
fedux_org-stdlib-0.7.16 lib/fedux_org_stdlib/command/run_command.rb
fedux_org-stdlib-0.7.15 lib/fedux_org_stdlib/command/run_command.rb
fedux_org-stdlib-0.7.14 lib/fedux_org_stdlib/command/run_command.rb
fedux_org-stdlib-0.7.12 lib/fedux_org_stdlib/command/run_command.rb
fedux_org-stdlib-0.7.11 lib/fedux_org_stdlib/command/run_command.rb
fedux_org-stdlib-0.7.10 lib/fedux_org_stdlib/command/run_command.rb
fedux_org-stdlib-0.7.8 lib/fedux_org_stdlib/command/run_command.rb
fedux_org-stdlib-0.7.7 lib/fedux_org_stdlib/command/run_command.rb
fedux_org-stdlib-0.7.6 lib/fedux_org_stdlib/command/run_command.rb
fedux_org-stdlib-0.7.5 lib/fedux_org_stdlib/command/run_command.rb
fedux_org-stdlib-0.7.4 lib/fedux_org_stdlib/command/run_command.rb
fedux_org-stdlib-0.7.3 lib/fedux_org_stdlib/command/run_command.rb
fedux_org-stdlib-0.7.2 lib/fedux_org_stdlib/command/run_command.rb
fedux_org-stdlib-0.7.1 lib/fedux_org_stdlib/command/run_command.rb
fedux_org-stdlib-0.7.0 lib/fedux_org_stdlib/command/run_command.rb