Running a script from Groovy

raoulsson picture raoulsson · Aug 26, 2009 · Viewed 18.1k times · Source

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!

Answer

John Flinchbaugh picture John Flinchbaugh · Aug 26, 2009

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

println "ls -la".execute().text