Class: Bolt::Transport::Local::Shell

Inherits:
Object
  • Object
show all
Defined in:
lib/bolt/transport/local/shell.rb

Instance Method Summary collapse

Instance Method Details

#execute(*command, options) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bolt/transport/local/shell.rb', line 10

def execute(*command, options)
  command = [options[:env]] + command if options[:env]

  if options[:stdin]
    stdout, stderr, rc = Open3.capture3(*command, stdin_data: options[:stdin], chdir: options[:dir])
  else
    stdout, stderr, rc = Open3.capture3(*command, chdir: options[:dir])
  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