1
votes

Am am trying to automated some of my work using groovy scripts on windows. I figured that this would be great start to learning groovy. Most of the part I use groovy to execute tedious CMD commands however I have few issued that are bugging me.

First one is that I can't find a way to terminate groovy script say:

if (!new File('c:\\myDir').exists)

Seconds - problem

"cmd /c doStuff".execute()

now I read that this is a good and short way to execute commands on CMD but i peaked at the source code and every 'execute()' method is marked as deprecated, but my biggest problem is that I can't seem to figure out how to stream the results in real time of e.g.:

println 'cmd /c mvn clean install'.execute(null, new File('sourcePath')).text 

this statement only prints out results once the whole build is complete. So is there any solution for this ?

Thanks.

1

1 Answers

3
votes

Try:

def p = 'cmd /c mvn clean install'.execute(null, new File('sourcePath'))
p.consumeProcessOutput( System.out, System.out )
p.waitFor()