Class: DTR::Cmd

Inherits:
Object show all
Defined in:
lib/dtr/shared/utils/cmd.rb

Class Method Summary collapse

Class Method Details

.execute(cmd, options = {:error_output_log_level => :error}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dtr/shared/utils/cmd.rb', line 19

def self.execute(cmd, options = {:error_output_log_level => :error})
  return true if cmd.nil? || cmd.empty?
  DTR.info {"Executing: #{cmd.inspect}"}
  output = %x[#{cmd} 2>&1]
  # don't put the following message into a block which maybe passed to remote process
  status = $?.exitstatus
  DTR.info {"Execution is done, status: #{status}"}
  if status != 0
    DTR.send(options[:error_output_log_level], "#{cmd.inspect} output:\n#{output}")
  end
  $?.exitstatus == 0
end