Hello,
when i try to execute the following code,
nothing happens und the programm will newer come to end.
Process aProcess;
String
externalCall="C:\\extern\\busakshamban\\v41\\jakarta-tomcat\\webapps\\jCatalog\\workarea\\supplier\\sBusak+Shamban\\documents\\xml\\bat\\publication2pdf.bat
C:\\extern\\busakshamban\\v41\\jakarta-tomcat\\webapps\\jCatalog\\workarea\\supplier\\sBusak+Shamban\\documents\\xml\\temp.xml
C:\\extern\\busakshamban\\v41\\jakarta-tomcat\\webapps\\jCatalog\\workarea\\supplier\\sBusak+Shamban\\documents\\xml\\bat\\publication2pdf.xsl
C:\\extern\\busakshamban\\v41\\jakarta-tomcat\\webapps\\jCatalog\\workarea\\supplier\\sBusak+Shamban\\documents\\xml\\bat\\publication2pdf.fo
C:\\extern\\busakshamban\\v41\\jakarta-tomcat\\webapps\\jCatalog\\workarea\\supplier\\sBusak+Shamban\\Publication\\3B2_o-ring\\pdf\\3B2_o-ring_109.pdf";
aProcess = Runtime.getRuntime().exec(externalCall);
BufferedReader procout =
new BufferedReader(new InputStreamReader(
aProcess.getInputStream()));
BufferedReader errout =
new BufferedReader(new InputStreamReader(
aProcess.getErrorStream()));
String line;
while ((line = procout.readLine()) != null) {
System.out.println(line);
}
while ((line = errout.readLine()) != null) {
System.out.println(line);
}
procout.close();
errout.close();
if (aProcess!=null)
{ aProcess.waitFor();
aProcess.exitValue();
aProcess.destroy();
}
When i try to execute the external call in the dos prompt it will work
well.
What could be the problem? Maybe to less memory.
Thank you for your help.
Thomas
Arnaud Berger - 17 Jun 2005 15:35 GMT
Hi,
Do your println statements print something ?
Maybe readLine() could block if the app never sends a line separator....
Regards,
Arnaud
> Hello,
>
[quoted text clipped - 3 lines]
> Process aProcess;
> String
externalCall="C:\\extern\\busakshamban\\v41\\jakarta-tomcat\\webapps\\jCatal
og\\workarea\\supplier\\sBusak+Shamban\\documents\\xml\\bat\\publication2pdf
.bat
C:\\extern\\busakshamban\\v41\\jakarta-tomcat\\webapps\\jCatalog\\workarea\\
supplier\\sBusak+Shamban\\documents\\xml\\temp.xml
C:\\extern\\busakshamban\\v41\\jakarta-tomcat\\webapps\\jCatalog\\workarea\\
supplier\\sBusak+Shamban\\documents\\xml\\bat\\publication2pdf.xsl
C:\\extern\\busakshamban\\v41\\jakarta-tomcat\\webapps\\jCatalog\\workarea\\
supplier\\sBusak+Shamban\\documents\\xml\\bat\\publication2pdf.fo
C:\\extern\\busakshamban\\v41\\jakarta-tomcat\\webapps\\jCatalog\\workarea\\
supplier\\sBusak+Shamban\\Publication\\3B2_o-ring\\pdf\\3B2_o-ring_109.pdf";
> aProcess = Runtime.getRuntime().exec(externalCall);
>
[quoted text clipped - 29 lines]
>
> Thomas
Sebastian Scheid - 17 Jun 2005 16:15 GMT
[snip]
> String line;
> while ((line = procout.readLine()) != null) {
[quoted text clipped - 4 lines]
> System.out.println(line);
> }
You should have each loop in an extra thread. Imagine the process doesn't
write anything to out but only to err. But the errorstream is not read until
the process finishes (=> procout.readLine() == null). And if the buffer of
the errstream is full, the process waits until it is free again. But that
cannot be the case before the process finishes => deadlock.
Does that solve the problem?
You may want to read
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html .
Regards
Sebastian
tschneider@sdz-medien.de - 20 Jun 2005 08:24 GMT
Hello Sebastian,
thank you very much for your help. The problem was really a deadlock
because errout also produces an output.
I solved the problem by using threads.
Regards
Thomas