【问题标题】:Why lein repl blocks STDERR为什么 lein repl 会阻止 STDERR
【发布时间】:2020-02-28 13:33:04
【问题描述】:

为什么 lein repl 会阻止 STDERR。我在没有项目的情况下运行lein repl,也运行lein repllein run,但在打印到STDERR 时遇到问题。例如,当连接到 NREPL(不同的终端选项卡)并运行时:

(.println System/err "something")

我在启动终端窗口中看不到任何打印内容 - 仅在 repl 中。如何让 STDERR 在两者中打印,因为它用于 SYSTEMD 日志记录。 我使用最新的 Leiningen,项目是使用 app 模板生成的。

【问题讨论】:

  • 奇怪,这是我得到的:lein repl user=> (.println System/err "bubu") bubu nil
  • 请添加您的 clojure、leiningen 版本以及您的 ~/.lein/profiles.clj 的内容。 FWIW 我对这些东西的组合与您发布的 sn-p 打印效果很好。
  • 哦,所以你的真正问题是关于给期刊写信的?这现在清楚了很多。我会开始阅读github.com/clojure-emacs/cider-nrepl/blob/master/src/cider/…,或者你的堆栈中实际使用的任何中间件。

标签: clojure leiningen


【解决方案1】:

lein repl 没有这样的事情。你可以自己测试一下:

# stop our individual writes from overlapping
with_lock() { exec {lock_fd}>>./tty_write_lock; flock "$lock_fd"; "$@"; exec {lock_fd}>&-; } 

lein repl 3>&2 \
           > >(while IFS= read -r line; do with_lock printf 'O:<%q>\n' "$line" >&3; done) \
          2> >(while IFS= read -r line; do with_lock printf 'E:[%q]\n' "$line" >&3; done) \
          3>&- <<'EOF'
(.println System/err "something on stderr")
(.println System/out "something on stdout")
EOF

...其中包含,以及其他输出:

O:<$'user=> (.println System/err "something on stderr")\E[50G\E[8G\E[51G'>
E:[something\ on\ stderr]
O:<nil>
O:<$'user=> (.println System/out "something on stdout")\E[50G\E[8G\E[51G'>
O:<something\ on\ stdout>
O:<nil>

如您所见,something on stdout 位于O:&lt;...&gt; 内部,由进程替换处理标准输出创建;而something on stderrE:[...] 内部,由处理stderr 的进程替换创建。


换个角度看:

{ strace -f -e write lein repl 2>&1 | egrep 'write[(][12],'; } <<'EOF'
(.println System/err "something on stderr")
(.println System/out "something on stdout")
EOF

...在其输出中包含以下系统调用:

[pid 10467] write(2, "something on stderr", 19) = 19
[pid 10467] write(1, "something on stdout", 19) = 19

...如您所见,stderr 正确写入 FD 2,而 stdout 正确写入 FD 1。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-18
    • 1970-01-01
    • 2011-10-16
    • 2011-05-20
    • 2011-03-27
    • 1970-01-01
    相关资源
    最近更新 更多