I'm trying to display the result log data of a long running process that I've kicked off using groovy's String.execute() method.I can do this for example:command = "ls -la"Process proc = command.execute().textAnd I get the out put as expected.However, if the command is some long running process like a slowly running TestNG test which prints out logging data as it runs, I'm unable to execute it and see the logging in real time.
def executeProc(cmd) {
def proc = "cmd /c ${cmd}".execute()
proc.in.eachLine {line ->
println line
}
println proc.err.text
proc.exitValue()
}
// Test it
def cmd = "cd ${my_dir} && mvn.bat ${skip_tests} ${clean} install"
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()
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() // executes the commandOutputStream outputStream = new FileOutputStream("stdout.txt")OutputStream errorStream = new FileOutputStream("stderror.txt")proc.waitForProcessOutput(outputStream, errorStream) // NOTE: since groovy 1.6.5println "Executing a testng jar"