Execute long process and collect stdout and stderr Recipe 1 def command = """ java -Xms512m -Xmx1024m \ -classpath test-suite-package-3.jar org.testng.TestNG \ -testjar test-suite-package-3.jar \ -d ./test-output-final/ """ Process proc = command.execute() OutputStream outputStream = new FileOutputStream('stdout.txt') OutputStream errorStream = new FileOutputStream('stderror.txt') proc.waitForProcessOutput(outputStream, errorStream) Recipe 2 def proc = '/path/to/longRunningProcess'.execute( null, new File('/path/to/workingDirectory') ) new File('/path/to/output.txt').withWriter { outFile -> proc.in.eachLine { line -> def tokens = line.tokenize '\t' outFile.writeLine "${tokens.join(',')}" } } proc.waitFor()