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
On MacOS or Linux this works:
user=> (require '[clojure.java.shell :as sh])
nil
user=> (sh/sh "ls" "-la")
...
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)