Clojure - how to run a program without piping output?

I want to use something like shell-out [ http://richhickey.github.com/clojure-contrib/shell-out-api.html ], but without capturing any output. Of course, the output can be transferred for printing, but this is slightly less than desirable (for example, in the event of a subprocess failure).

change

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

+6
source share
2 answers

Also see this third-party library

https://github.com/Raynes/conch

It provides direct access to streams.

+5
source

EDIT: before clarification

You can wrap the shell command with sh and then pipe in / dev / null, for example:

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

This will disable the output before moving on to clojure.

EDIT: After clarification

Print transfer and stderr for printing should work as long as the output comes out fast enough. If you want something with a continuous output of error messages and a standard output, you should refer to the source for the "sh" function.

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

+3
source

Source: https://habr.com/ru/post/894795/


All Articles