谁能为我解释一下clojure中的sh以便执行系统命令? [英] Can anyone explain me about the sh in clojure in order to execute the system command?
问题描述
我正在使用Mac OS.我想使用(使用'[clojure.java.shell:only [sh]])
执行系统命令,就像在 https://clojuredocs.org/clojure.java.shell/sh 但无法理解诸如可以通过一种语法传递多少个参数之类的东西.
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://clojuredocs.org/clojure.java.shell/sh but wasn't able to understand things like how many parameters can be passed in one syntax, etc.
在Windows中,我尝试了(sh"cmd""//C""dir")
,但该命令仍然有效,但在Mac OS中,如何执行上述语法?此外,我想传递的参数不仅限于 dir
.例如,我要执行(sh"cmd""/c""mged""test.g")
.注意: mged
和 test.g
是从 Brl-Cad
引用的.
In windows I have tried (sh "cmd" "/C" "dir")
and it was working but in Mac OS, how do I execute the above syntax? Moreover I want to pass more parameters than just dir
. For example, I want to execute (sh "cmd" "/c" "mged" "test.g")
.
NOTE: mged
and test.g
are referred from Brl-Cad
.
我想使用上面的示例绘制一个球体.
I want to draw a sphere using above example.
推荐答案
clojure.java.shell
仅使用给定参数(以及:env
和:dir
和...-参见文档).因此,首先最有可能在OSX/Unix上没有 cmd
,但是通常会有一个外壳.与外壳上的 cmd/c
相同的是 -c
. -c
接受一个参数,您可以在此处编写"shell代码"-这意味着您可以使用管道,重定向,env-vars ...-因此,如果您只想执行带有参数的工具,请使用:
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")
(请注意,"shell代码"只是一个参数)
(note that the "shell code" is just one argument)
这篇关于谁能为我解释一下clojure中的sh以便执行系统命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!