Reputation: 2849
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?
Upvotes: 55
Views: 17450
Reputation: 487
You could use the babashka library to run shell commands in Clojure. An example would be
#!/usr/bin/env bb
(require '[clojure.java.shell :refer [sh]])
(sh "top")
Upvotes: 0
Reputation: 18005
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.
Upvotes: 2
Reputation: 24443
(use '[clojure.java.shell :only [sh]])
(sh "free")
(sh "top" "-bn1")
See also: http://clojuredocs.org/clojure_core/clojure.java.shell/sh
Upvotes: 80