Why does read-line not return after hitting ENTER (seems like a hang) using lein run, but works with lein repl?

clojure, leiningen

Solution

Try lein trampoline run, it works.

The following is from leiningen FAQ:

Q: I don't have access to stdin inside my project.

A: This is a limitation of the JVM's process-handling methods; none of them expose stdin correctly. This means that functions like read-line will not work as expected in most contexts, though the repl task necessarily includes a workaround. You can also use the trampoline task to launch your project's JVM after Leiningen's has exited rather than launching it as a subprocess.

Problem

The problem at hand is that when I run my program with `lein run` it gets to the `(read-line)` part and I can't get out of it, meaning: read-line never returns. Here is the relevant code: ``` (def command (atom "")) (defn print-prompt [] (print "prompt> ") (flush) ) (defn ask-for-input [] (print-prompt) (let [x (str (read-line))] (println (str "User input: " x)) (reset! command x) ) ) ``` I never see the "User input: " string on screen. The strange part is, if I run `lein repl` and call `(ask-for-input)` then it works correctly :S

Original source