module ScaBox::Runner
Public Instance Methods
command?(name)
click to toggle source
TODO: find a better way to do this
# File lib/scabox_sdk/runner.rb, line 8 def command?(name) `which #{name}` $?.success? end
run_cmd(cmd)
click to toggle source
# File lib/scabox_sdk/runner.rb, line 13 def run_cmd(cmd) print_debug(cmd) if @opts.verbose if command?(cmd[0]) run_cmd_with_timeout(cmd) else print_error("Command not found: #{cmd[0]}") exit 1 end end
run_cmd_with_timeout(cmd)
click to toggle source
def run_cmd
(cmd)
if command?(cmd[0]) @framework.print_debug("Command: #{cmd.join(' ')}") if @framework.verbosity > 1 #run_cmd_orig(cmd) run_cmd_with_timeout(cmd) else @framework.print_error("Command: '#{cmd[0]}' not found") if @framework.verbosity > 1 @errors += 1 end
end
# File lib/scabox_sdk/runner.rb, line 36 def run_cmd_with_timeout(cmd) out_reader = '' err_reader = '' Open3.popen3(*cmd) do |stdin, stdout, stderr, wait_thr| # https://stackoverflow.com/questions/8952043/how-to-fix-hanging-popen3-in-ruby stdin.close_write output, pid = [], wait_thr.pid begin Timeout.timeout(@timeout) do begin err_reader = Thread.new { stderr.read } rescue IOError end out_reader = stdout.read #output = [stdout.read, stderr.read] Process.wait(pid) end rescue Errno::ECHILD rescue Timeout::Error print_error('Timed out - Skipping...') Process.kill('HUP', pid) exit 1 end [out_reader, wait_thr.value] end end