问题
Cannot connect remote REPL properly
Here are the steps I do:
- Start local repl instance: lein repl
- 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), orConnect 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