Class: Dropkick::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/dropkick/command.rb

Class Method Summary collapse

Class Method Details

.secure_exec(command, arguments = []) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/dropkick/command.rb', line 5

def self.secure_exec(command, arguments = [])
  stdout = nil
  stderr = nil
  exit_code = nil 

  command_array = arguments.unshift(command)

  duration = Benchmark.realtime do
    Open3.popen3(*command_array) do |stdin, out, err, wait_thr|
      stdout = out.read
      stderr = err.read
      exit_code = wait_thr.value.exitstatus
    end
  end
  
  CommandResult.new(stdout, stderr, exit_code, duration)
end