-->

Groovy中使用的命令报价执行外部RTC命令(Groovy execute external RT

2019-10-20 02:26发布

我有我试图从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)
}

Answer 1:

你需要调用waitFor()proc不是cmd



文章来源: Groovy execute external RTC command with quotes in the command
标签: groovy rtc