Module: Teabag::Utility
- Included in:
- Coverage, Drivers::PhantomjsDriver, Instrumentation
- Defined in:
- lib/teabag/utility.rb
Instance Method Summary collapse
-
#which(cmd) ⇒ String?
Cross-platform way of finding an executable in the $PATH.
Instance Method Details
#which(cmd) ⇒ String?
Cross-platform way of finding an executable in the $PATH. stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/teabag/utility.rb', line 13 def which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each do |ext| exe = "#{ path }/#{ cmd }#{ ext }" return exe if File.executable?(exe) end end nil end |