I am executing testng.xml(having 40 Testcases) from cmd shell using Apache.commons.exec.Executor in java with following code :
public static void executeBatch(String folderLoc) throws Exception {
try {
String cmd_for_testng = "java -cp " + "D:\\project\\libs\\*;D:\\project\\bin" + " org.testng.TestNG testng.xml";
CommandLine cl = CommandLine.parse("cmd.exe /k" + dir +" && cd \"" + "D:\\project" + "\" && " + cmd_for_testng);
DefaultExecuteResultHandler resultHandler;
ExecuteWatchdog watchdog;
final Executor executor;
resultHandler = new DefaultExecuteResultHandler();
watchdog = new ExecuteWatchdog(-1L);
executor = new DefaultExecutor();
executor.setStreamHandler(new PumpStreamHandler(new LogOutputStream() {
@Override
protected void processLine(final String line, @SuppressWarnings("unused") int level) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
if (line.toLowerCase().indexOf("error") > -1) {
System.out.println(line+"\n");
} else if (line.toLowerCase().indexOf("warn") > -1) {
System.out.println(line+"\n");
} else {
System.out.println(line+"\n");
}
}
});
}
}));
executor.setExitValue(1);
executor.setWatchdog(watchdog);
executor.execute(cl, resultHandler);
} catch (Exception e) {
e.printStackTrace();
}
}
However it hangs after executing 11-14 testcases , it stops writing into console and hangs forever. If I kill its process, the execution of testng.xml suddenly resumes however as now I have killed the executor process , I can't see console output.