def run(command)
name = command_name(command)
Logger.message "Running system utility '#{ name }'..."
begin
out, err = '', ''
ps = Open4.popen4(command) do |pid, stdin, stdout, stderr|
stdin.close
out, err = stdout.read.strip, stderr.read.strip
end
rescue Exception => e
raise Errors::CLI::SystemCallError.wrap(e, "Failed to execute system command on \#{ RUBY_PLATFORM }\nCommand was: \#{ command }\n")
end
if ps.success?
unless out.empty?
Logger.message(
out.lines.map {|line| "#{ name }:STDOUT: #{ line }" }.join
)
end
unless err.empty?
Logger.warn(
err.lines.map {|line| "#{ name }:STDERR: #{ line }" }.join
)
end
return nil
else
raise Errors::CLI::SystemCallError, "'\#{ name }' Failed on \#{ RUBY_PLATFORM }\nThe following information should help to determine the problem:\nCommand was: \#{ command }\nExit Status: \#{ ps.exitstatus }\nSTDOUT Messages: \#{ out.empty? ? 'None' : \"\\n\#{ out }\" }\nSTDERR Messages: \#{ err.empty? ? 'None' : \"\\n\#{ err }\" }\n"
end
end