Sha256: dc2815de446f3a57e4aeef8aae90ee989b63d6ef0033fb0d627a7b4308724fb7
Contents?: true
Size: 899 Bytes
Versions: 51
Compression:
Stored size: 899 Bytes
Contents
#encoding: utf-8 require 'open3' module Riemann module Babbler module Plugins module Helpers # helper: stdout+stderr и exit status def shell(*cmd) exit_status=nil err =nil out =nil Timeout::timeout(plugin.timeout) { Open3.popen3(*cmd) do |stdin, stdout, stderr, wait_thread| err = stderr.gets(nil) out = stdout.gets(nil) [stdin, stdout, stderr].each { |stream| stream.send('close') } exit_status = wait_thread.value end } if exit_status.to_i > 0 err = err.chomp if err raise 'Error while running shell: ' + err.to_s elsif out return out.strip else # exit status 0, no stdout '' end end end end end end
Version data entries
51 entries across 51 versions & 1 rubygems