This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-16
Channels
- # 100-days-of-code (1)
- # announcements (1)
- # beginners (93)
- # boot (46)
- # cider (40)
- # cljdoc (4)
- # cljs-dev (7)
- # clojure (78)
- # clojure-conj (12)
- # clojure-dev (17)
- # clojure-italy (5)
- # clojure-nl (10)
- # clojure-spec (34)
- # clojure-uk (36)
- # clojurescript (56)
- # code-reviews (6)
- # core-async (31)
- # cursive (12)
- # datascript (9)
- # datomic (19)
- # devops (2)
- # editors (3)
- # emacs (6)
- # events (2)
- # figwheel (1)
- # figwheel-main (11)
- # fulcro (59)
- # graphql (10)
- # hyperfiddle (3)
- # keechma (5)
- # leiningen (26)
- # luminus (1)
- # nrepl (5)
- # re-frame (5)
- # reitit (10)
- # shadow-cljs (64)
- # spacemacs (29)
- # tools-deps (6)
- # uncomplicate (8)
- # vim (2)
- # yada (4)
I have this code:
(ns where-print
(:require
[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 🙂