Making Runtime.exec() wait

The point of this thread is really that I feel like I owe Giant2 some more points for helping beyond what was needed... Others who wish to answer this question, though, see here for the details of my problem (I am willing to split points):

Though the details are at the link above, I will summarize the issue:
I am using Runtime.getRuntime().exec("javac") to compile a java source file. However, I later JAR the file, so I need the Runtime command to finish compiling before continuing in the program (what it does otherwise is simply starts the compiling process alongside the rest of my program and does both at once).

Now, if I can get a code example I'll award the points and be off to finish my program!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You just want a waitFor() in there:

Process proc = Runtime.getRuntime().exec("javac");

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Depends whether you want to do it in one thread or not. You can use waitFor if so. If you're using more than one thread and are compiling\jarring asynchronously, you need to use some form of semaphore
CI-Ia0sAuthor Commented:
It's one thread, and it's working. :)

Keteracel, I'm giving you the majority of the points for your example. I'm just waiting for Giant2 because I do owe him something for his help on this in the other thread. As soon as he posts here I'll split 'em up and dish 'em out.
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

>>It's one thread, and it's working. :)

Oh - from your other Q it looked like more than one thread ;-)
CI-Ia0sAuthor Commented:
Well... I am running several threads, but the jarring and javacing occur in the same thread. Plus, I'd think waitFor would still work anyway... Java waits to finish any process I call before moving on to the in the thread, right? (i.e. I call method Encrypt() from class EncryptData and it finishes that before continuing with the rest of the program).

Anyway, waiting on Giant2 now...
>>but the jarring and javacing occur in the same thread


>>Java waits to finish any process I call before moving on to the in the thread, right?


Mick BarryJava DeveloperCommented:
If you're interested here's an example that'll post your command output to a swing text area
CI-Ia0sAuthor Commented:
Cool. I was wondering how to get to that info... anyway, thanks. Now where is Giant2!?!?!
>Now where is Giant2
Sorry, I was out of office.
I believe the answer I gave at the post (Q_21074134.html#11674022) was correct:

I told in the that post:
>yes. You can use the waitFor method over the Process you use to start the javac.

Bye, Giant.
CI-Ia0sAuthor Commented:
Yup, it was. I just haven't worked with the Process class before and needed a code example. (I can see why you thought one wasn't necessary). ;)

You have both been awarded points. Thanks for your help!
Thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.