Groovy execute external RTC command with quotes in the command

余生长醉 提交于 2019-12-13 02:59:14

问题


I have an external command I am trying to run from Groovy. The command has quotes embedded in the command and I'm getting the following error:

Caught: groovy.lang.MissingMethodException: No signature of method: java.lang.String.waitFor() is applicable for argument types: () values: []

I have tried escaping the quotes with backslashes, but that does not work either.

Here is an example of the command:

scm workspace add-components test-workspace -s test-stream "test1" "test2" -r url

I have tried building this as:

scm workspace add-components test-workspace -s test-stream "\test1\" \"test2\" -r url

Groovy method:

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

回答1:


You need to call waitFor() on proc not on cmd.



来源:https://stackoverflow.com/questions/23568755/groovy-execute-external-rtc-command-with-quotes-in-the-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!