]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/core/utils/utils.rb
utils: Utils.try_exec
[user/henk/code/ruby/rbot.git] / lib / rbot / core / utils / utils.rb
index 92df73ff8e62af09a2943426edaf45feb2a666cb..fb9b1f651094f42fff7f42654348e80705b197ca 100644 (file)
@@ -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.