【问题标题】:Remote REPL no output, how to dublicate output in PrintWriter?(Clojure)远程 REPL 无输出,如何在 PrintWriter 中复制输出?(Clojure)
【发布时间】:2019-09-06 17:00:43
【问题描述】:

无法正确连接远程 REPL

这是我做的步骤:

  1. 启动本地 repl 实例: lein repl
  2. 通过远程 repl 实例连接到本地(我通过 Intellij IDEA 完成)

在此之后,代码中的每个输出都只在本地复制中,在远程复制中什么都没有

我需要什么:查看两个 repl 实例中的所有输出

我找到了部分解决方案,此代码将一个 repl 的输出重新绑定到另一个。只需在远程运行它,所有输出都会转到它

(defn rebind-output []
  (prn "Rebinding output...")
  (System/setOut (PrintStream. (WriterOutputStream. *out*) true))
  (System/setErr (PrintStream. (WriterOutputStream. *err*) true))
  (alter-var-root #'*out* (fn [_] *out*))
  (alter-var-root #'*err* (fn [_] *err*)))

out - 是 PrintWriter 的实例

但是我需要的是:查看 BOTH repls 输出相同,怎么做?

【问题讨论】:

    标签: clojure output read-eval-print-loop


    【解决方案1】:

    我似乎不认为您对如何连接到现有 REPL(您从命令行使用 lein repl 启动的 REPL)感到困惑。您是否检查了Cursive manual 中的 Remote REPLs 部分?

    通常,您只需要以下之一:

    • 在已经使用 Leiningen 管理的项目上从 Intellij 本身启动 REPL(例如,它已经有一个 project.clj 文件),或者

    • 连接到一个已经在运行的 REPL,一个在同一主机上运行的,或者在不同的机器上。

    如果您自己在控制台中启动lein repl,您会看到它在启动时打印一些消息:

    $ lein repl
    nREPL server started on port 39919 on host 127.0.0.1 - nrepl://127.0.0.1:39919
    

    在本例中,服务器开始在我自己的主机(127.0.0.1localhost)上侦听端口 39919(每次您使用 lein repl 启动 REPL 时,此端口都会更改)。您需要在 Intellij 中输入这些值才能连接到此 REPL。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多