I am trying to use sh from clojure.java.shell. In the REPL
, it works fine but from a script, it gets stuck.
(ns tutorial.shell
(:use clojure.java.shell))
(println (:out (sh "ls" )))
What should I fix?
The problem is that sh
uses futures and Clojure programs which use futures or agents hang around a bit before quitting when they have nothing more to do due to how some internal machinery works.
To get around this, add
(shutdown-agents)
at the end of your script, which terminates that piece of machinery. (So it does more than the name promises in that futures are also affected.)
Note that this cannot be undone and therefore should not be used at the REPL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With