小编blk*_*001的帖子

Groovy:如何在groovy中执行复杂的shell命令?

我希望能够执行嵌套的shell命令.例如;

final String cmd = 'for i in pom.xml projects.xml; do find . -name $i | while read fname; do echo $fname; done;done'
Run Code Online (Sandbox Code Playgroud)

我尝试了以下语法,但无法让它运行.

  1. def result = cmd.execute();
  2. def result = ['sh', '-c', cmd].execute();
  3. def result = ('sh -c for i in pom.xml projects.xml; do find . -name $i | while read fname; do echo $fname; done;done').execute()

我很感激这里的帮助.

shell groovy

2
推荐指数
1
解决办法
8166
查看次数

标签 统计

groovy ×1

shell ×1