How to print to STDERR in Clojure?

clojure

Solution

There is no specific function for this, however you can dynamically rebind the var holding the stream that `println` writes to like this:

(println "Hello, STDOUT!")

(binding [*out* *err*]
  (println "Hello, STDERR!"))

In my REPL, the colour indicates the stream (red is STDERR):

Problem

The `println` function writes to `STDOUT`. How can we write messages to `STDERR` instead? ``` (println "Hello, STDOUT!") ```

Original source