我无法使用Groovy执行带有反引号的shell命令。以下是一个简化的示例:
println "echo `date`".execute().text
我搜索了一下,试图想出如何以某种方式逃脱它们,但没有成功。
如果您尝试使用以下代码会发生什么:
println ["bash", "-c", "echo `date`"].execute().text
标签的存在,文本被解释为一个段落。
"echo `date`".execute()
如果您在字符串上调用execute()
,那么Java的Runtime#exec(String)
将被使用。这种情况下,它只是将字符串分解为标记,并使用参数执行程序echo
。
`date`
$(date)
但这是shell (bash)的语法,必须通过bash执行。
def process = ["bash", "-c", command].execute(); println process.text
- Dag