繁体   English   中英

clojure — 如何在没有管道的情况下运行程序 output?

[英]clojure — how to run a program without piping it's output?

I want to use something like shell-out [ http://richhickey.github.com/clojure-contrib/shell-out-api.html ], but without capturing the any output. 当然可以将 output 传递给打印,但这有点不太理想(例如,在子进程可能失败的情况下)。

编辑

对不起,我希望 output 的子进程与父进程相同的stdout

另请参阅此第三方库

https://github.com/Raynes/conch

它提供对流的直接访问。

编辑:澄清之前

您可以使用 sh 将 shell 命令包装,然后将 pipe 包装到 /dev/null ,如下所示:

 (clojure.java.shell/sh "sh" "-c" "echo hello > /dev/null")
 ;; {:exit 0, :out "", :err ""}

这将使 output 在到达 clojure 之前静音。

编辑:澄清后

只要 output 足够快地出来,通过 output 和 stderr 打印应该可以工作。 如果您想要具有连续 output 错误消息和标准 output 的东西,查看“sh” function 的来源应该会有所帮助。

Personally, I would make my own version of clojure.java.shell/sh and for each stream, create a thread that pipes the output directly to out using something like IOUtils.copy from org.apache.commons.io.IOUtilsin

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM