Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Runtime.exec( ) is hanging....

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have an app the uses Runtime to fire an [.exe]. the [.exe] is suppose to load a file. i see from the command window that the [.exe] kicked off...but it just hangs when it's suppose to process the file.
when i run the statement from the command-line, it runs fine...and returns back to the command prompt when done.
one thing, the posloader.exe creates it's own log file...
below is my source...please help:

thank you in advance...
sin sai
[ July 23, 2002: Message edited by: Jim Yingst ]
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't really take the time to figure out what might be going wrong with your code. Following is the code I always use to run os commands, its always worked for me, maybe it will fix your problem.
Its copied almost verbatim from the java tutorial example:
OSExec.java:


StreamGobbler.java:


You might also look at :http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
It details some common problems with runtime.exec
Hope this helps
Michael Crutcher
 
sin sai
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you michael...but i've read that article already...
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sinsai - please take a moment to read our display name policy and then edit your display name to include a space between first and last names. Thanks.
I added [code] tags to your previous post to make the indentation readable.
So, you read the Daconta article. Did you try the code? One thing you may not realize is that StreamGobbler actually runs in a separate thread. This can be important. With the code you show, it's possible that the error stream's buffer is full with some message for you, but you're waiting to read from standard output first. This creates a hang, since the process remains open and thus the standard output does not return null, at least until the error message has been read. It's definitely a good idea to use StreamGobbler or something like it. May well solve your problem.
If you continue to have errors afterwards, I suggest putting in enough print statements that you can work out exactly which statements have executed and which haven't. Which particular line is the process hanging at?
[ July 23, 2002: Message edited by: Jim Yingst ]
 
sin sai
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
jim...sorry about the name.
i'll implement the Thread.
thank you...
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try:
Process batch = run.exec("cmd posloader.exe FXOpt c:\\all_test.pos /C");
Basically, invokes the command prompt and executes your exe from there.
 
sin sai
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
michael and jim...thank you!!!
 
I am Arthur, King of the Britons. And this is a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic