How to execute system commands?

Solution 1:

(use '[clojure.java.shell :only [sh]])
(sh "free")
(sh "top" "-bn1")

See also: http://clojuredocs.org/clojure_core/clojure.java.shell/sh

Solution 2:

You should be able to use the Java Runtime.exec method as follows:

(import 'java.lang.Runtime)

(. (Runtime/getRuntime) exec "your-command-line-here")

The Runtime.exec method returns a Process object that you can query to get the standard output etc. as needed.

Solution 3:

If you are willing to get a little higher in term of abstractions (although no that high), I would recommend Conch, as I found it to make very readable code.