Question

Why does trying to read a line from console with a BufferedReader freeze Leiningen REPL?

lein repl
nREPL server started on port 65142
REPL-y 0.2.0
Clojure 1.5.1
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)

user=> (import [java.io BufferedReader BufferedWriter InputStreamReader])
java.io.InputStreamReader
user=> (.readLine (BufferedReader. (InputStreamReader. System/in)))
Was it helpful?

Solution

Calling lein repl actually launches a new background server process for evaluating code; what you see in the console is a client process that sends code to the server for evaluation and then displays the results that are returned. What I suspect is happening here is that, when the REPL server evaluates System/in, it's actually referring to stdin of the server process, which you can't write to from the client.

Replacing (InputStreamReader. System/in) with *in* should allow your code to work from the REPL as well as when launched directly with lein run or java.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top