diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-04-11 12:38:58 +0200 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-04-11 13:12:00 +0200 |
commit | 22d753aed9b358aae47a68edfa035dcf73580f52 (patch) | |
tree | 650fce9cbbd71b3cd9d61d460e2a3f5da7b5cd1d /lib | |
parent | 6912969287479a9f2afa20d06aa7ab54d66db063 (diff) |
utils: Utils.try_exec
An auxiliary method to test-run external programs and see if they run
without problem
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rbot/core/utils/utils.rb | 19 |
1 files changed, 19 insertions, 0 deletions
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. |