Groovy在命令中使用引号执行外部RTC命令

Groovy在命令中使用引号执行外部RTC命令,groovy,rtc,Groovy,Rtc,我有一个试图从Groovy运行的外部命令。命令中嵌入了引号,我得到以下错误: Caught: groovy.lang.MissingMethodException: No signature of method: java.lang.String.waitFor() is applicable for argument types: () values: [] 我尝试过用反斜杠来转义引号,但这也不起作用 以下是该命令的一个示例: scm workspace add-components tes

我有一个试图从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
Groovy方法:

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)
}

您需要在
proc
上调用
waitFor()
而不是在
cmd
上粘贴您尝试运行的groovy代码。