X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Frbot%2Fcore%2Futils%2Futils.rb;fp=lib%2Frbot%2Fcore%2Futils%2Futils.rb;h=fb9b1f651094f42fff7f42654348e80705b197ca;hb=22d753aed9b358aae47a68edfa035dcf73580f52;hp=92df73ff8e62af09a2943426edaf45feb2a666cb;hpb=6912969287479a9f2afa20d06aa7ab54d66db063;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git 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.