wood burning stoves 2.0*
The moose likes Java in General and the fly likes ProcessBuilder and Process Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "ProcessBuilder and Process" Watch "ProcessBuilder and Process" New topic
Author

ProcessBuilder and Process

Amber Vaidya
Ranch Hand

Joined: Oct 14, 2003
Posts: 42
Hi All,

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?

Any help is appreciated.

Thanks,
Amber
[ October 26, 2007: Message edited by: Bear Bibeault ]
Ed Thompson
Ranch Hand

Joined: Jan 20, 2006
Posts: 43
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!
Ed Thompson
Ranch Hand

Joined: Jan 20, 2006
Posts: 43
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.
Amber Vaidya
Ranch Hand

Joined: Oct 14, 2003
Posts: 42
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.

That seems feasible. Let me try it out.
Thanks !!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ProcessBuilder and Process