The output is sent to the console instead of REPL when using streams in Eclipse / CounterClockWise

I tried this code from this guide:

(defn my-fn [ms]
  (println "entered my-fn")
  (Thread/sleep ms)
  (println "leaving my-fn"))

(let [thread (Thread. #(my-fn 1))]
  (.start thread)
  (println "started thread")
  (while (.isAlive thread)
    (print ".")
    (flush))
  (println "thread stopped"))

When I execute it, part of the result appears in the REPL, and the other part is displayed in the console (which appears because I usually hide it because I do not use it).

I want to send all the output to the REPL window, how can I do this?

+5
source share
1 answer

This is because it is *out*not tied to a REPL record in a new thread. You can link it manually:

(let [thread (let [out *out*] 
               (Thread. #(binding [*out* out] 
                           (my-fn 1))))]
  (.start thread)
  (println "started thread")
  (while (.isAlive thread)
    (print ".")
    (flush))
  (println "thread stopped"))
+6
source

All Articles