Sha256: 9c1767dbe8f1a39a9ba2040a89f1f37585a676999d997a185610a11cfe61b5c9

Contents?: true

Size: 795 Bytes

Versions: 3

Compression:

Stored size: 795 Bytes

Contents

require 'open3'
require 'bolt/node/output'

module Bolt
  module Transport
    class Local
      class Shell
        def execute(*command, options)
          if options[:env]
            env = options[:env].each_with_object({}) { |(k, v), h| h["PT_#{k}"] = v }
            command = [env] + command
          end

          if options[:stdin]
            stdout, stderr, rc = Open3.capture3(*command, stdin_data: options[:stdin])
          else
            stdout, stderr, rc = Open3.capture3(*command)
          end

          result_output = Bolt::Node::Output.new
          result_output.stdout << stdout unless stdout.nil?
          result_output.stderr << stderr unless stderr.nil?
          result_output.exit_code = rc.to_i
          result_output
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bolt-0.17.2 lib/bolt/transport/local/shell.rb
bolt-0.17.1 lib/bolt/transport/local/shell.rb
bolt-0.17.0 lib/bolt/transport/local/shell.rb