This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
No. You need to "empty" the two Streams. Google for the classic article by Michael Daconta: Michael Daconta When Runtime.exec() won't, and follow what it says there. You can simplify the exercise slightly with the ProcessBuilder class, but follow Daconta's examples otherwise.
Read through it and understand both what the Runtime.exec() is and is not, but also make sure you understand (and implements) the parts about consuming the output and error streams - failing to consume both (at the same time) can lead to the command stalling as it waits for buffers to free up.
<dern. Too Slow>
Joined: Feb 10, 2009
Thanks for your suggestions. I read the article by Michel Daconta and understood most of it. The problem I am facing now with the approach suggested in the article is getting the exit value of the .cmd file.
I should have mentioned what actually I was doing there. I wanted to export a database table as a csv file. This is what I have done.
When I call the .cmd from Java, I dont get any exit code: When I run the Java class it hangs after printing <ERROR>
That's because you're only reading from the error stream. The process' output buffer is probably full, so you'll need to start reading from the Process' input stream as well. That's what the article is all about. And because you can't read from two streams simultaneously in one thread you'll need to use a new thread for the input stream. That, or use ProcessBuilder and redirect the error stream so you can read everything from the input stream.