Module: Nexoform::Bash
- Defined in:
- lib/nexoform/shell.rb
Class Method Summary collapse
- .escape_double_quotes(str) ⇒ Object
- .run_command(command, print_stdout = false) ⇒ Object
- .run_command_loud(command) ⇒ Object
Class Method Details
.escape_double_quotes(str) ⇒ Object
19 20 21 |
# File 'lib/nexoform/shell.rb', line 19 def self.escape_double_quotes(str) str.gsub('"', '\\"') end |
.run_command(command, print_stdout = false) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# 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) ⇒ Object
33 34 35 36 37 38 39 40 |
# 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 |