• 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

ProcessBuilder and Process

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ed Thompson
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 !!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic