• 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

waitFor method of a process object not working

 
Ranch Hand
Posts: 83
Netbeans IDE MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the error in this program

In this program i am trying to execute a batch file using java.
output "wait completed" is printed even before the process p completed ! why is that so? it is working well with eclipse not working in netbeans i m using netbeans 6.9 with jdk 1.6
 
Ranch Hand
Posts: 129
Netbeans IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also had the same problem, long time ago and was unable to solve. Any help is greatly appreciated.
 
vinayak jog
Ranch Hand
Posts: 83
Netbeans IDE MySQL Database Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nitin Surana wrote:I also had the same problem, long time ago and was unable to solve. Any help is greatly appreciated.


I have done a small work around and its working as of now its not a legal solution

and remove p.waitFor
add small code at the end of the batch file


when work is over batch file executes the exit statement and it will return controll to the program then p.getInputStream().read() will return -1 this will indicate end of execution untill -1 is got the main thread will wait for process. "This worked for me" might work for you also
 
Ranch Hand
Posts: 227
Eclipse IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your questions will be answered in this article. I highly recommend going through it before using Runtime.exec().
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic