Question

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)
}
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top