1
votes

I am using a Java library in Clojure. It does output many things directly to the console using System.out.println.

I am using the latest Cider with Emacs. I am starting Cider with cider-jack-in. However, I can see these outputs. I thought they would be copied to the nrepl-server buffer, but it is not.

I also tried to run (alter-var-root #'*out* (constantly *out*)) in the REPL, but no success.

What am I missing in how this should be done, if it can be done at all.

1
Take a look in the messages buffer, I think they go there - Timothy Pratley
The messages buffer simply logs the communication between CIDER and the nREPL server. - Bozhidar Batsov
The output should appear in the REPL buffer normally. If it doesn't - file a ticket on github and we'll look into the problem. - Bozhidar Batsov
@BozhidarBatsov ok, will retry and test and report if there is an issue, thanks! - Neoasimov

1 Answers

2
votes

You need to replace the java.io.PrintStream assigned to System.out with one that will forward everything to clojure.core/*out* (which is an instance of java.io.PrintWriter). To do that you have to create an adapter from PrintStream to PrintWriter. I haven't found an existing one in the Java SDK API but there is one in Apache Commons IO (or you can implement it by yourself):

(import (java.io PrintStream)
        (org.apache.commons.io.output WriterOutputStream))

(-> *out*
    (WriterOutputStream.)
    (PrintStream.)
    (System/setOut))

From now on when you call System.out.println anywhere in your JVM the output will be passed to clojure.core/*out*.