Can anyone explain me about the sh in clojure in order to execute the system command?

后端 未结 2 1006
一向
一向 2021-01-29 06:25

I\'m using Mac OS. I want to execute a system command using (use \'[clojure.java.shell :only [sh]]), like in How to execute system commands?. I have read https://cl

2条回答
  •  天命终不由人
    2021-01-29 07:13

    clojure.java.shell just spawns the process with the given arguments (and :env and :dir and ... - see the doc). So first of all there is most likely no cmd on OSX/Unix, but there usually is a shell. And the "same" as cmd /c on the shell is -c. -c takes one argument and you can write your "shell code" there - that means you can use pipes, redirects, env-vars, ... - so if you just want to execute a tool with a param, use:

    (sh "mged" "test".g")
    

    If you want "shell features" use:

    (sh "/bin/sh" "-c" "echo ${TERM} | tr x u")
    

    (note that the "shell code" is just one argument)

提交回复
热议问题