I have some java code that submits jobs to a utility running on Sun Solaris using the ProcessBuilder class of 1.5
The code is fairly simple. I am reading the error and output streams in separate threads too.
Now, my problem is that the utility, I am using, does not wait for the job to complete. Rather, it returns as soon as it submits the job(And returns the Pid of the process that is running the job). This makes proc.waitFor() to return with 0 even though actually the job/process is still executing.
Any idea on how I can make Java wait for the actual process to finish?
Without more details I am guessing, but I suspect that the utility you are calling (not a Java program?) is forking a process to do the real work, then terminating the process you started to get the ball rolling.
Without knowing more about the utility, you may be able to do something with wrapping the utility call in a shell script, and controlling true process termination with the termination of the utility call within the shell script.
That is, if you can write the shell script in such a way that it does not terminate until your processing is complete, you could then call the shell script from Java, and processing should proceed as you desire.
Even if the voices <i>aren't</i> real, they still have some good ideas!
Joined: Jan 20, 2006
Another interpretation - your utility is submitting a job request that another process is executing. In this case, the utility is done when the job is submitted. In this scenario, you would need some way of interfacing with the process that actually executes the request, not the one that submits it.
Again, this is usually possible through some sort off shell/batch script. Whether you include the submit/monitor in a single resuest to a script, or break them up is up to you.
Joined: Oct 14, 2003
Alright guys, so what you are saying is, I should write a shell script that submits the job to the utility and track the progress of the PID in the script (wait till the pid is active before finishing the script). From my Java code, I should call the shell script and wait for the script to finish executing.