module Nexoform::Bash

Public Class Methods

escape_double_quotes(str) click to toggle source
# File lib/nexoform/shell.rb, line 19
def self.escape_double_quotes(str)
  str.gsub('"', '\\"')
end
run_command(command, print_stdout = false) click to toggle source
# File lib/nexoform/shell.rb, line 23
def self.run_command(command, print_stdout = false)
  stdout = `bash -c "#{escape_double_quotes(command)}"`
  puts stdout if print_stdout
  OpenStruct.new(
    success?: $?.exitstatus.zero?,
    exitstatus: $?.exitstatus,
    stdout: stdout
  )
end
run_command_loud(command) click to toggle source
# File lib/nexoform/shell.rb, line 33
def self.run_command_loud(command)
  exitstatus = system("bash -c \"#{escape_double_quotes(command)}\"")
  OpenStruct.new(
    success?: exitstatus,
    exitstatus: exitstatus ? '0' : '1', # we lose the true exit code
    stdout: '' # we lose stdout too
  )
end