This discussion is archived
3 Replies Latest reply: Oct 18, 2012 8:31 AM by sabre150 RSS

How to Start the Process Immediately in Java

904394 Newbie
Currently Being Moderated
Hi
Through my java code i am trying to run the batch file as a process by using following code:

Process process = new ProcessBuilder("c:/test.bat").start();

This starts the process correctly but it takes time to start.. But when i click the batch file manaully process starts immediately.
Is there any way i can achieve to start the process immediately just like manual click.

Also once this process is started do i need to destroy it?.. Why i am asking i cant wait till the process finish because it takes time to finish.


Thanks
Raj.
  • 1. Re: How to Start the Process Immediately in Java
    sabre150 Expert
    Currently Being Moderated
    The process starts as soon as it can so you are stuffed if it takes too long.

    You don't need to wait till the process finishes! Just run it in a separate thread !

    You should spend a lot of time reading ALL the sections of http://www.javaworld.com/jw-12-2000/jw-1229-traps.html and then to implement ALL the recommendations. Even though this is concerned with a Process obtained from Runtime.exec() it still applies to one obtained from ProcessBuilder. You may be tempted to take some short cuts and only implement some of the recommendations but this will just jump up and bite you later.
  • 2. Re: How to Start the Process Immediately in Java
    gimbal2 Guru
    Currently Being Moderated
    sabre150 wrote:
    You don't need to wait till the process finishes! Just run it in a separate thread !
    Err, -running- a process in a thread? Perhaps you want to reword that ;)
  • 3. Re: How to Start the Process Immediately in Java
    sabre150 Expert
    Currently Being Moderated
    gimbal2 wrote:
    sabre150 wrote:
    You don't need to wait till the process finishes! Just run it in a separate thread !
    Err, -running- a process in a thread? Perhaps you want to reword that ;)
    Don't think so. Maybe I needed to capitalise Process and Thread but I don't think there is any ambiguity.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points