Class: ExecuteShellCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/apollo_commons_ruby/ExecuteCommand.rb

Instance Method Summary collapse

Instance Method Details

#run_command(cmd) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/apollo_commons_ruby/ExecuteCommand.rb', line 4

def run_command(cmd)
  post_content = "stdin"
  stdout_str, stderr_str, exit_code = Open3.capture3(cmd, :stdin_data=>post_content)

  # command output in console is printed in the following lines of code
  puts stdout_str
  puts stderr_str
  
  # based on the result, success or error messages are returned. 
  # these logs are used to send flock notification
  if exit_code == 0
    return stdout_str
  else
    return stderr_str
  end
end