how to use execute() in groovy to run any command

Posted by drake on Stack Overflow See other posts from Stack Overflow or by drake
Published on 2010-03-11T18:29:34Z Indexed on 2010/03/11 18:34 UTC
Read the original article Hit count: 249

Filed under:
|

I usually build my project using these two commands from command line (dos)

G:\> cd c:
C:\> cd c:\my\directory\where\ant\exists
C:\my\directory\where\ant\exists> ant -Mysystem
...
.....
build successful

What If I want to do the above from groovy instead? groovy has execute() method but following does not work for me:

def cd_command = "cd c:"
def proc = cd_command.execute()
proc.waitFor()

it gives error:

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)

© Stack Overflow or respective owner

Related posts about groovy

Related posts about ant