小编dra*_*ake的帖子

如何在groovy中使用execute()来运行任何命令

我通常使用命令行(dos)中的这两个命令构建我的项目

G:\> cd c:
C:\> cd c:\my\directory\where\ant\exists
C:\my\directory\where\ant\exists> ant -Mysystem
...
.....
build successful
Run Code Online (Sandbox Code Playgroud)

如果我想从groovy做上述事情呢?groovy有execute()方法,但以下对我不起作用:

def cd_command = "cd c:"
def proc = cd_command.execute()
proc.waitFor()
Run Code Online (Sandbox Code Playgroud)

它给出了错误:

Caught: java.io.IOException: Cannot run program "cd": CreateProcess error=2, The
 system cannot find the file specified
        at ant_groovy.run(ant_groovy.groovy:2)
Run Code Online (Sandbox Code Playgroud)

ant groovy

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

标签 统计

ant ×1

groovy ×1