7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/remon/helper.rb', line 7
def cmd(command, error_msg: nil, return_output: true, env: {}, shell: false)
if command.is_a? Array
command_arr = command
command_str = command.join(" ")
else
command_arr = command.split
command_str = command
end
logger.debug command_str
run_command = shell ? command_str : command_arr
output = if return_output
IO.popen(env, run_command) { |f| f.read }
else
system(env, run_command, 2 => 1)
end
exitstatus = $?.exitstatus
if exitstatus != 0
error_msg ||= "non zero exit for \"#{command_str}\""
raise Error, error_msg
end
return output
end
|