How to execute system commands?

后端 未结 3 853
攒了一身酷
攒了一身酷 2021-02-01 12:26

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

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-01 13:21

    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.

提交回复
热议问题