Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / June 2005

Tip: Looking for answers? Try searching our database.

Runtime.getRuntime().exec Problem

Thread view: 
tschneider@sdz-medien.de - 17 Jun 2005 14:17 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.