From 22d753aed9b358aae47a68edfa035dcf73580f52 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sat, 11 Apr 2009 12:38:58 +0200 Subject: utils: Utils.try_exec An auxiliary method to test-run external programs and see if they run without problem --- lib/rbot/core/utils/utils.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lib/rbot') diff --git a/lib/rbot/core/utils/utils.rb b/lib/rbot/core/utils/utils.rb index 92df73ff..fb9b1f65 100644 --- a/lib/rbot/core/utils/utils.rb +++ b/lib/rbot/core/utils/utils.rb @@ -293,6 +293,25 @@ module ::Irc } end + # Try executing an external program, returning true if the run was successful + # and false otherwise + def Utils.try_exec(command, *args) + IO.popen("-") { |p| + if p.nil? + begin + $stderr.reopen($stdout) + exec(command, *args) + rescue Exception => e + Kernel::exit! 1 + end + Kernel::exit! 1 + else + debug p.readlines + end + } + debug $? + return $?.success? + end # Safely (atomically) save to _file_, by passing a tempfile to the block # and then moving the tempfile to its final location when done. -- cgit v1.2.3