Created
December 1, 2011 17:10
-
-
Save derekgreer/1418266 to your computer and use it in GitHub Desktop.
Rake which method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def which(cmd) | |
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] | |
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| | |
exts.each { |ext| | |
sep = File::ALT_SEPARATOR || File::SEPARATOR | |
exe = "#{path}#{sep}#{cmd}#{ext}" | |
return exe if File.executable? exe | |
} | |
end | |
return nil | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment