How to make System command calls in Java/Groovy?

前端 未结 4 1631
眼角桃花
眼角桃花 2021-01-31 16:01

What I want to do is invoke maven from a groovy script. The groovy script in question is used as a maven wrapper to build J2EE projects by downloading a tag and invoking maven o

4条回答
  •  野的像风
    2021-01-31 16:32

    The simplest way to invoke an external process in Groovy is to use the execute() command on a string. For example, to execute maven from a groovy script run this:

    "cmd /c mvn".execute()
    

    If you want to capture the output of the command and maybe print it out, you can do this:

    print "cmd /c mvn".execute().text
    

    The 'cmd /c' at the start invokes the Windows command shell. Since mvn.bat is a batch script you need this. For Unix you can invoke the system shell.

提交回复
热议问题