Skip to content

Instantly share code, notes, and snippets.



Last active Jan 24, 2020
What would you like to do?
which - find binary on PATH accounting for PATHEXT on Windows - (JVM Clojure and babashka)
(require '[ :as cji])
(require '[clojure.string :as cs])
(defn which
(let [paths (clojure.string/split (or (System/getenv "PATH") "")
(re-pattern (System/getProperty "path.separator")))
;; for windows
pathexts (clojure.string/split (or (System/getenv "PATHEXT") "")
(re-pattern (System/getProperty "path.separator")))]
;; adapted work by taylorwood
(for [path (distinct paths)
pathext pathexts
:let [exe-file ( path (str bin-name pathext))]
:when (.exists exe-file)]
(.getAbsolutePath exe-file)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment