Wednesday 25 January 2012

Separate Threads for Process Input and Error Stream ~CMD mode execution using java Runtime ~



I had to run a bat file from cmd(command) mode using java and flatten the output of the cmd mode to a text file for instance and my block of code looks as below and its quite simple as well.I've used the InputStream and ErrorStream to serve the purpose.


and a while loop to iterate and write to text file.




while ((s = stdError.readLine()) != null) {
//put to a file

}




while ((s = stdInput.readLine()) != null) {
//put to a file

}


But,I have ended up in a problem ,the thread seems to have ended up blocking and the bat file(which consists of triggering my web driver test cases)was also blocked.The quick work around was to have two anonymous inner class of Thread and it solved the problem.


This is only for quick work around before I look into non blocking io's.






Thanks for reading..... cheers :) :)



No comments:

Post a Comment