开发者

clojure -- how to run a program without piping it's output?

开发者 https://www.devze.com 2023-03-27 00:39 出处:网络
I want to use something like shell-o开发者_运维问答ut [ http://richhickey.github.com/clojure-contrib/shell-out-api.html ], but without capturing the any output. Of course the output can be passed to p

I want to use something like shell-o开发者_运维问答ut [ 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 (e.g. in the case that the subprocess may fail).

edit

Sorry, I want the subprocess to output to the same stdout as the parent process.


Also see this third party library

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:

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

This will silence the output before getting to clojure.

EDIT: After Clarification

Passing output and stderr to print should work as long as the output comes out quickly enough. If you want something with continuous output of error messages and standard output, looking at the source for the "sh" function should help.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消