Thursday, February 16, 2012

Shell/Command line execution

//def cmd = "cmd /C dir"
def cmd = ["cmd","/C","dir g*.bat"] // more flexible format

//Groovyish Java//
Runtime r = Runtime.runtime
Process p = r.exec(cmd.toArray(new String()))
BufferedReader inp = new BufferedReader(new InputStreamReader(p.getInputStream()))
while (line = inp.readLine()) { println line }

//Groovy!//
println cmd.execute().text

No comments:

Post a Comment