远程REPL无输出,如何在PrintWriter中复制输出? [英] Remote REPL no output, how to dublicate output in PrintWriter?(Clojure)

查看:54
本文介绍了远程REPL无输出,如何在PrintWriter中复制输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法正确连接远程REPL

Cannot connect remote REPL properly

这是我要做的步骤:

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

此后,代码中的每个输出仅在本地repl中出现,而在远程repl中则没有任何结果

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

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

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

我找到了部分解决方案,此代码将一个repl的输出重新绑定到另一个.只需在远程目录中运行它,所有输出都将传递给它

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 -是PrintWriter的实例

out - is intstance of PrintWriter

但是我需要的是:看到两个repls都输出相同的内容,怎么做?

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

推荐答案

我似乎不认为您对如何连接到现有的REPL感到困惑(使用 lein从命令行启动的那个)repl ).您是否检查了 Cursive手册中的远程REPL 部分?

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:

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

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

连接到已经运行的REPL,该REPL是在同一主机或另一台计算机上运行的.

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

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

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

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

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.

这篇关于远程REPL无输出,如何在PrintWriter中复制输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆