Let me give a simple example:
In a Linux environment I have a Grails script, and I want to get all my directories using ls command:
def ls = "ls".execute()
println ls
// result is java.lang.UNIXProcess@f16b42
Instead of getting the process ID, I want to get the same output I get into a terminal
Ps.: This is just a example, I don’t really need to list directories.
The quick way is:
HOWEVER! If it writes a lot of output, the reader will fill up, and then it will all block. So, you need to do something like:
Of course, you might want to check the exitCode that
proc.waitFor()returns, and do something better with the error stream then send it toSystem.err, but you get the idea 😉