Groovy在命令中使用引号执行外部RTC命令 [英] Groovy execute external RTC command with quotes in the command

查看:168
本文介绍了Groovy在命令中使用引号执行外部RTC命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个外部命令,我试图从Groovy运行。该命令在命令中嵌入了引号,并且出现以下错误:

 抓住:groovy.lang.MissingMethodException:No方法的签名:java.lang.String.waitFor()适用于参数类型:()values:[] 

我尝试用反斜杠转义引号,但这也行不通。



以下是一个命令示例:

  scm workspace add-components test-workspace -s test-streamtest1test2-r url 



我试图将其构建为:

  scm工作区添加组件测试工作区-s测试流\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 不在 cmd 上调用 waitFor() >。


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.

这篇关于Groovy在命令中使用引号执行外部RTC命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆