Java executing commands in Operating System
<p>I have a Java program that executes specific commands into the OS. Am also using Process.waitfor() as showing in the code below to indicates if the execution completed successfully or failed. </p>

<p>My question is, is there any other way to avoid using process.waitfor(), Is there a way to use while loop and perform certain action until the process is completed?</p>

<pre><code>            Runtime rt = Runtime.getRuntime();

  Process p = rt.exec(cmdFull);

        BufferedReader inStream = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String inStreamLine = null;
        String inStreamLinebyLine=null;
        while((inStreamLine = inStream.readLine()) == null) {
          inStreamLinebyLine = inStreamLinebyLine+"\n"+inStreamLine;
        }


        try {
            rc = p.waitFor();

        } catch (InterruptedException intexc) {
            System.out.println("Interrupted Exception on waitFor: " +
                               intexc.getMessage());
        }
</code></pre>

<p>Waht I wish to do, is something like this</p>

<pre><code>            Runtime rt = Runtime.getRuntime();

  Process p = rt.exec(cmdFull);

        BufferedReader inStream = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String inStreamLine = null;
        String inStreamLinebyLine=null;
        while((inStreamLine = inStream.readLine()) == null) {
          inStreamLinebyLine = inStreamLinebyLine+"\n"+inStreamLine;
        }


        try {

   while ((rc = p.waitFor()) == true ) { // This is made up, I don't even think it would work
    System.out.println('Process is going on...');
   }


        } catch (InterruptedException intexc) {
            System.out.println("Interrupted Exception on waitFor: " +
                               intexc.getMessage());
        }
</code></pre>

<p>Thanks,</p>
