문제

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)
}
도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top