我有我试图从Groovy中运行一个外部命令。 该命令有嵌入在命令报价,我发现了以下错误:
Caught: groovy.lang.MissingMethodException: No signature of method: java.lang.String.waitFor() is applicable for argument types: () values: []
我试图逃避反斜杠引号,但这并不能工作。
下面是一个命令的例子:
scm workspace add-components test-workspace -s test-stream "test1" "test2" -r url
我曾尝试建立这种为:
scm workspace add-components test-workspace -s test-stream "\test1\" \"test2\" -r url
常规方法:
void addComponents(String repository, String name, String flowTarget, ArrayList components) {
String compStr = components.toString().replace('[', '\"').replace(']', '\"').replace(', ', '\" \"')
String cmd = """scm workspace add-components ${name} -s ${flowTarget} ${compStr} -r ${repository}"""
println cmd
def proc = cmd.execute()
cmd.waitFor()
getReturnMsg(proc)
}