Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Making Runtime.exec() wait

Posted on 2004-08-01
11
2,770 Views
Last Modified: 2009-04-29
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): http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21074134.html#11674022

Though the details are at the link above, I will summarize the issue:
I am using Runtime.getRuntime().exec("javac File.java") 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!
0
Comment
Question by:CI-Ia0s
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 9

Accepted Solution

by:
keteracel earned 40 total points
ID: 11687850
You just want a waitFor() in there:

Process proc = Runtime.getRuntime().exec("javac File.java");
proc.waitFor();
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11689035
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
0
 
LVL 3

Author Comment

by:CI-Ia0s
ID: 11689505
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.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 86

Expert Comment

by:CEHJ
ID: 11689532
>>It's one thread, and it's working. :)

Oh - from your other Q it looked like more than one thread ;-)
0
 
LVL 3

Author Comment

by:CI-Ia0s
ID: 11689545
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...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11689576
>>but the jarring and javacing occur in the same thread

OK

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

Yes

0
 
LVL 92

Expert Comment

by:objects
ID: 11689766
If you're interested here's an example that'll post your command output to a swing text area

http://www.objects.com.au/java/examples/util/SwingExec.do
0
 
LVL 3

Author Comment

by:CI-Ia0s
ID: 11690023
Cool. I was wondering how to get to that info... anyway, thanks. Now where is Giant2!?!?!
0
 
LVL 12

Assisted Solution

by:Giant2
Giant2 earned 35 total points
ID: 11691188
>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.
0
 
LVL 3

Author Comment

by:CI-Ia0s
ID: 11694732
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!
0
 
LVL 12

Expert Comment

by:Giant2
ID: 11694763
Thank you.
:-)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
java stored proc example 9 44
hibernate insert example 13 34
eclipse apache tomcat admin console 52 121
How to configure empty element in XML Document parser? 15 36
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question