views:

495

answers:

2

In order to get my setup a bit closer to "one click deployment", I would like to use groovy scripts to start/stop other processes controlled by bat scripts, running in different parts of the filesystem and even on different machines.

How to execute these scripts and how to do it from their respective working directory?

I know Java's

java.lang.Runtime's exec()

However there are lots of issues with this and I wondered if Groovy had some kind of shorthand for this as well?

Thanks!

+1  A: 

Groovy added an execute() method to plain old String, so try this:

println "ls -la".execute().text
John Flinchbaugh
I'm still not sure about changing the working directory.
John Flinchbaugh
Thanks so far! Like it a lot!
raoulsson
+1  A: 

The execute() method can be used to change directories if you prefix it with the "cmd /c" command, and then use ampersand (assuming Windows) to chain commands together.

Example, assuming you want to go to subdirectory subdir and run a couple of batch files from there:

println "cmd /c cd subdir & batch1.bat & batch2.bat".execute().text

Not sure if there isn't a better way, but this does work.

seansand