• 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

Regarding Executing a batch file in Java

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone

I have a question in the below code. I am trying to run a "server.bat" in a specified location. The batch file runs and waits for multiple clients and it stops when we close it. Now my problem is when I run the below code my server is running perfectly but the program waits for the batch to complete inspite of me not giving waitfor method for the process. My program shouldn't wait for the batch file to complete. It has to run the command in a new window and control the other flow of program which is not done here in this program. Can anyone help me whats the problem is?




Thanks for your help
-Vijay
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are still waiting for the process to finish, as that's the only moment when the process' output will end. So the JavaWorld article "When Runtime.exec() won't" is still valid here -- read from the error stream as well.
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Rob says, you will block your output if you don't empty both streams, but it appears to be the output stream you are forgetting, and the error stream you are reading from.

By the way: reserve System.exit(0) for normal termination; use System.exit(i) where i is a non-zero int for abnormal termination, as you have in your catch block.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic