Search code examples
clojure

How to execute system commands?


How can I execute system specific commands and get their response in Clojure? For example, let's assume we're on a Linux machine, how can I call top or free, and get their results for further processing?


Solution

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

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