I'm announcing
java.shell2. It is backward compatible with clojure.java.shell. This is a Clojure library to facilitate launching of sub-processes and piping (streaming) data.
Features
- A declarative syntax for defining new processes to specify input, output, encoding, and other behavior
- Handling for common use-cases (i.e. pass stdout/err of the process to the same destination as the parent, merge stderr of the process to stdout, output directly to a File, etc)
- The pipe macro handles all the complexity of managing multipe streams and threads for streaming data through multiple processes and clojure functions.
- Backward compatible with existing code that uses clojure.java.shell (i.e. a drop-in replacement)
Shell has additional predicates like :pass, which will connect STDOUT or STDERR of the process to the STDOUT/ERR of the parent JVM.
(sh "wc" "-l" :in input :err :pass :out (io/file "/tmp/foo"))
So the above form reads input (which can be a file, stream, string, etc), forwards the output to a file and redirects STDERR to STDERR of the JVM.
And here's an example of a pipe:
my-filter-fn ;A clojure function -- data is streamed
See the README for more details and many examples in the unit tests.
I know there are other shell libraries for Clojure. My main motivation is that I wanted something closer to the clojure.java.shell api.
Marc Limotte