clojure lein (read-line) stdin woes

谁说胖子不能爱 提交于 2019-12-08 17:23:13

问题


So regular clojure repl works fine, (read-line) collects input, then echos it. Using lein repl though, never echoes any input characters, nor does it ever allows me to return from any stdin reading commands.

I'm sure it has something to do with rebinding in, but was wondering if there is a workaround/fix?

Thanks.


回答1:


This is due to a bug in ant; it prevents the stdin stream from the subprocess it launches from being used. But the telnet trick should work since lein repl launches a socket repl server; it works fine here.




回答2:


Connect to the REPL via telnet.

$ lein repl
REPL started; server listening on localhost:63849.
user=> 
[1]+  Stopped                 lein repl
$ telnet localhost 63849
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
user=> (read-line)
hello
"hello"
user=>



回答3:


This works for me now: Wrap your read-line calls with the macro with-read-line-support which is in ns swank.core [since swank-clojure 1.4+ I believe]:

(use 'swank.core)
(with-read-line-support 
  (println "a line from Emacs:" (read-line)))

Thanks to Tavis Judd for the fix.



来源:https://stackoverflow.com/questions/3790889/clojure-lein-read-line-stdin-woes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!