简体   繁体   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. I want to use something like shell-out [ http://richhickey.github.com/clojure-contrib/shell-out-api.html ], but without capturing the any output. Of course the output can be passed to print, but this is slightly less than desirable (eg in the case that the subprocess may fail).当然可以将 output 传递给打印,但这有点不太理想(例如,在子进程可能失败的情况下)。

edit编辑

Sorry, I want the subprocess to output to the same stdout as the parent process.对不起,我希望 output 的子进程与父进程相同的stdout

Also see this third party library另请参阅此第三方库

https://github.com/Raynes/conch https://github.com/Raynes/conch

It provides direct access to the streams.它提供对流的直接访问。

EDIT: Before Clarification编辑:澄清之前

You can wrap the shell command with a sh and then pipe to /dev/null like so:您可以使用 sh 将 shell 命令包装,然后将 pipe 包装到 /dev/null ,如下所示:

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

This will silence the output before getting to clojure.这将使 output 在到达 clojure 之前静音。

EDIT: After Clarification编辑:澄清后

Passing output and stderr to print should work as long as the output comes out quickly enough.只要 output 足够快地出来,通过 output 和 stderr 打印应该可以工作。 If you want something with continuous output of error messages and standard output, looking at the source for the "sh" function should help.如果您想要具有连续 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 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