Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In clojure, sh is stuck

Tags:

clojure

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?

like image 926
viebel Avatar asked Feb 20 '12 03:02

viebel


1 Answers

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.

like image 141
Michał Marczyk Avatar answered Sep 25 '22 07:09

Michał Marczyk