| Author |
Executing exe using getRuntime.exec() through servlet
|
Sanjaya Sugiarto
Ranch Hand
Joined: Mar 25, 2004
Posts: 229
|
|
Hello everyone, I have a problem. I need to execute an exe. I have tried with a simple main method and it works like a charm. But as I try to integrate into Tomcat, it hangs. The program uses pdftohtml to convert a pdf into html. Here is the code: It hangs just before the waitFor(). Have you guys any idea how to solve this? Many thanks. PS: I tried this with tomcat bundled with Netbeans 5.
|
<a href="http://www.wi.hs-furtwangen.de" target="_blank" rel="nofollow">Business Information Technology - Hochschule Furtwangen University, Germany</a>
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12271
|
|
Sounds like a very familiar problem - when you exec an external program, the Process takes over the standard input, output and error streams. If you do not provide for consuming these streams, the program probably hangs indefinately because it is trying to write to the output and/or error stream. This is all covered in the java.lang.Process JavaDocs discussion. Bill
|
Java Resources at www.wbrogden.com
|
 |
Sanjaya Sugiarto
Ranch Hand
Joined: Mar 25, 2004
Posts: 229
|
|
Sorry for my ignorant, but how can I provide to consume those streams? In Javadoc there is no detail how to do that. Thanks.
|
 |
Sanjaya Sugiarto
Ranch Hand
Joined: Mar 25, 2004
Posts: 229
|
|
Hmmm....you meant: process.getErrorStream(); process.getInputStream(); process.getOutputStream(); Is adding those 3 lines before the waitFor should be enough? Or you meant something different? Thanks
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
Not enough. Read this.
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12271
|
|
Is adding those 3 lines before the waitFor should be enough? Or you meant something different?
Just obtaining the output streams is not enough, you have to provide for reading from them - just like it says in the JavaDocs for Process. Note that if your exe is producing an error, it will likely be reported as messages to either stderr or stdout. You will need a separate Thread to read each stream and write the result somewhere so you can check it later. You would only need to write to the stdin stream if your program requires keyboard input. Bill
|
 |
 |
|
|
subject: Executing exe using getRuntime.exec() through servlet
|
|
|