Module: Teaspoon::Utility
- Included in:
- Driver::Phantomjs, Exporter, Instrumentation
- Defined in:
- lib/teaspoon/utility.rb
Instance Method Summary collapse
-
#which(cmd) ⇒ Object
Cross-platform way of finding an executable in the $PATH.
Instance Method Details
#which(cmd) ⇒ Object
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
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/teaspoon/utility.rb', line 16 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.file?(exe) && File.executable?(exe) end end nil end |