Fork me on GitHub

I have this code:

(ns where-print
    [clojure.spec.alpha :as s]))

(s/def ::foo string?)

(defn -main
  [& args]
  (when-not (s/valid? ::foo 1)
    (s/explain ::foo 1)
    (System/exit 1)))
If I run clj -m where-print nothing is printed to stdout. Any idea how to prevent this from happening?


(System/exit 1) is a pretty brutal way to exit the program and it can quit the JVM before output is flushed. If you add (flush) before that exit, you should get your output.


It would also work if you did this:

(defn -main
  [& args]
  (when-not (s/valid? ::foo 1)
    (println (s/explain-str ::foo 1))
    (System/exit 1)))
since println will flush stdout to the newline (although your output will now have two newlines) @kenny


@seancorfield thanks. By brutal, are you hinting at a better way to exit the process with a unsuccessful exit code?


No. Just observing that it it immediately kicks off a shutdown of the JVM and some things may not get done that you are expecting 🙂


JVM — Unleash your inner Hulk!