Remote REPL no output, how to dublicate output in PrintWriter?(Clojure)

久未见 提交于 2021-01-29 09:31:09

问题


Cannot connect remote REPL properly

Here are the steps I do:

  1. Start local repl instance: lein repl
  2. Connect to local by remote repl instance(I do it through Intellij IDEA)

After this, every output in code goes only in local repl, in remote one there are nothing

What I need: to see all outputs in both repl instances

I have found partial solution, this code rebinds output of one repl to another. Just run it in remote one, and all output will go to it

(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 - is intstance of PrintWriter

However what I need is: see BOTH repls outputing the same, how to do it?


回答1:


I can't seem to think that you are confused about how to connect to an existing REPL (the one you launch from the command line with lein repl). Did you check the section Remote REPLs in the Cursive manual?

Generally, you want only one of these:

  • Launch the REPL from Intellij itself on a project that is already managed with Leiningen (eg. it already has a project.clj file), or

  • Connect to an already running REPL, one that is running on the same host, or in a different machine.

If you are starting lein repl yourself in a console, you'll see that it prints some messages on startup:

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

In this example, the server started listening on my own host (127.0.0.1 or localhost) on port 39919 (this port will change each time you launch the REPL with lein repl). You'll need to enter these values in Intellij to be able to connect to this REPL.



来源:https://stackoverflow.com/questions/55710752/remote-repl-no-output-how-to-dublicate-output-in-printwriterclojure

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