Wait for external program to finish

I'm doing this to run a program from the windows cmd in java:
 
    String[] com = {"cmd.exe", "/C", "Start", "runThis.exe"};
    Runtime.getRuntime().exec.(com);
 
The problem:  I need "runThis.exe" to finish running before my java code continues.  As it is now the code continues to run as soon as it launches runThis.exe.
qbawler311Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

CEHJCommented:
You need to do

int returnVal = process.waitFor();

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
WebstormCommented:
You may also need to read process output (stdout & stderr) :

        Runtime.getRuntime().exec.(com);

        Thread th_out,th_err;
        // Process. OUT
        (th_out=new Thread(){
            byte b[]=new byte[8192];
            InputStream inp=p.getInputStream();
            public void run()
            {
                try{
                    for(;;)
                    {
                        int sz=inp.read(b);
                        if (p_out!=null) p_out.write(b,0,sz);
                    }
                }catch(Exception e){}
            }
        }).start();

        // Process. ERR
        (th_err=new Thread(){
            byte b[]=new byte[8192];
            InputStream inp=p.getErrorStream();
            public void run()
            {
                try{
                    for(;;)
                    {
                        int sz=inp.read(b);
                        if (p_err!=null) p_err.write(b,0,sz);
                    }
                }catch(Exception e){}
            }
        }).start();

        int returnVal = process.waitFor();

        th_out.interrupt();
        th_err.interrupt();
WebstormCommented:
In the above code :

OutputStream p_out = System.out;
OutputStream p_err = System.err;

Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

WebstormCommented:
Instead, if you don't want to see output :

OutputStream p_out = null;
OutputStream p_err = null;

CEHJCommented:
:-)
qbawler311Author Commented:
right back at ya :-)
WebstormCommented:
:-(
qbawler311Author Commented:
sorry webstorm but i thought it would be infair to split points since CEHJ answered the question completely first.  Thanks for the extra info though. :-/
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
Java

From novice to tech pro — start learning today.