Executing shell commands in Clojure less than 1 minute read Code ;; executing_shell_commands.clj (use '[clojure.java.shell :only [sh]]) (require '[clojure.string :as str]) (sh "cal") (println (:out (sh "cal"))) (def curl_output (:out (sh "curl" "-X" "HEAD" "-I" "https://something.com"))) (println curl_output) (rest (str/split curl_output #"\n")) (def url "https://something.com") (as-> url x (sh "curl" "-X" "HEAD" "-I" x) (:out x) (str/split x #"\n") (nth x 2) (str/split x #":") (last x) (str/trim x)) (defn url-content-type [url] (as-> url x (sh "curl" "-X" "HEAD" "-I" x) (:out x) (str/split x #"\n") (nth x 2) (str/split x #":") (last x) (str/trim x))) (url-content-type "https://something.com") (url-content-type "https://mindaslab.github.io/me.jpg") Twitter Facebook LinkedIn Previous Next