Skip to content

Instantly share code, notes, and snippets.

@derekgreer
Created December 1, 2011 17:10
Show Gist options
  • Save derekgreer/1418266 to your computer and use it in GitHub Desktop.
Save derekgreer/1418266 to your computer and use it in GitHub Desktop.
Rake which method
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