gpt4 book ai didi

clojure - 为什么使用 lein run 按 ENTER 键后 read-line 不返回(看起来像是挂起),但使用 lein repl 却可以?

转载 作者:行者123 更新时间:2023-12-02 01:25:17 25 4
gpt4 key购买 nike

当前的问题是,当我使用 lein run 运行程序时,它会到达 (read-line) 部分,而我无法摆脱它,意思是:读取行永远不会返回。

相关代码如下:

(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)
)
)

我从未在屏幕上看到“用户输入:”字符串。奇怪的是,如果我运行 lein repl 并调用 (ask-for-input) 则它可以正常工作:S

最佳答案

尝试lein蹦床跑,它有效。

以下内容来自 leiningen 常见问题解答:

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.

关于clojure - 为什么使用 lein run 按 ENTER 键后 read-line 不返回(看起来像是挂起),但使用 lein repl 却可以?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10883188/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com