title: Java Loop InputStream until boolean = false
body: <p>I have this input stream that checks if I have a certain CAD file open or not. I am doing this by using an input stream to run a tasklist command with the name I want to check. I currently have a boolean that returns true if the specific CAD file isn't open. If the CAD file is open, it returns false. However, I want it to be able to loop this until the CAD file is open because as of right now I have to keep running it in order for it to work. I also need to be able to check this boolean from a separate class. I have it in my main right now so i could test it. My code looks like this...</p>
  
  <pre><code>public class AutoCadCheck {
  
  public static void main(String[] argv) throws Exception {
  
      String notOpen = "INFO: No tasks are running which match the specified criteria";
      StringBuilder textBuilder = new StringBuilder();
      String command = "tasklist /fi \"windowtitle eq Autodesk AutoCAD 2017 - [123-4567.dwg]";
      int i;
  
      InputStream myStream = Runtime.getRuntime().exec(command).getInputStream();
  
      while ((i = myStream.read()) != -1) {
          textBuilder.append((char) i);
      }
  
      String output = textBuilder.toString();
      boolean logical = output.contains(notOpen);
  
      if (logical) {
          System.out.println("DWG Not Open");
      } else {
          System.out.print(output);
      }
      myStream.close();
  }
  }
  </code></pre>
  
  <p>My other class is going to have an 'if statement' that checks whether my boolean "logical" is false, and if so, print something. I have tried every possible method I could think of, but I cannot get it to function the way I want it to. Every other thing I found involving looping an inputstream didn't really apply to my situation. So hopefully someone can help me out in achieving what I want to do.</p>