Using clojure.java.shell for long running tasks

213 views
Skip to first unread message

Matthew Boston

unread,
Nov 16, 2011, 2:48:41 PM11/16/11
to Clojure
How can I get clojure.java.shell/sh to print to stdout while running?
Currently, it waits until `sh` returns before I can access :out and
println it.

(:use clojure.java.shell)

(defn call-maven [& args]
(apply sh "mvn" args))

(defn maven-version []
(-> "-v" call-maven :out println))

Thanks for you help!

Phil Hagelberg

unread,
Nov 16, 2011, 2:53:55 PM11/16/11
to clo...@googlegroups.com
On Wed, Nov 16, 2011 at 11:48 AM, Matthew Boston
<matthew...@gmail.com> wrote:
> How can I get clojure.java.shell/sh to print to stdout while running?
> Currently, it waits until `sh` returns before I can access :out and
> println it.

I actually had to stop using clojure.java.shell/sh for this and just
used Runtime/exec directly precisely for this reason:

https://github.com/technomancy/leiningen/blob/master/src/leiningen/compile.clj#L171

I could clean this up and submit it as a patch upstream if it's
desired. Though on the other hand, the raw Runtime calls are not
horribly cumbersome.

-Phil

Matthew Boston

unread,
Nov 16, 2011, 4:59:02 PM11/16/11
to Clojure
Thanks, Phil. Works like a charm!

BTW, I'm working on the lein-mvn plugin which allows the use of maven
plugins inside leiningen projects.

On Nov 16, 2:53 pm, Phil Hagelberg <p...@hagelb.org> wrote:
> On Wed, Nov 16, 2011 at 11:48 AM, Matthew Boston
>
> <matthew.bos...@gmail.com> wrote:
> > How can I get clojure.java.shell/sh to print to stdout while running?
> > Currently, it waits until `sh` returns before I can access :out and
> > println it.
>
> I actually had to stop using clojure.java.shell/sh for this and just
> used Runtime/exec directly precisely for this reason:
>
> https://github.com/technomancy/leiningen/blob/master/src/leiningen/co...

Phil Hagelberg

unread,
Nov 16, 2011, 5:14:00 PM11/16/11
to clo...@googlegroups.com
On Wed, Nov 16, 2011 at 1:59 PM, Matthew Boston
<matthew...@gmail.com> wrote:
> Thanks, Phil. Works like a charm!
>
> BTW, I'm working on the lein-mvn plugin which allows the use of maven
> plugins inside leiningen projects.

Great; looking forward to it!

-Phil

Hugo Duncan

unread,
Nov 16, 2011, 5:29:54 PM11/16/11
to clo...@googlegroups.com
I took a slightly different approach to this, in pallet.shell, and added
an :async flag that returns the streams and the process

https://github.com/pallet/pallet/blob/master/src/pallet/shell.clj

Reply all
Reply to author
Forward
0 new messages