title: Java stuck in infinite loop executing a wmic command on Windows Server 2003
body: <p>I'm trying to get a list of running processes and their file paths on a Windows Server 2003 machine. I'm using the following code to try and do that:</p>
  
  <pre><code>protected Map&lt;String,String&gt; getProcesses() {
      Map&lt;String,String&gt; processes = new HashMap&lt;String,String&gt;();
      try {
          String line;
          Process p = null;
  
          // Windows
          if (OS.indexOf("win") &gt;= 0) {
              p = Runtime.getRuntime().exec("wmic process get description,executablepath");
              BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
              LOG.info("Entering while loop");
              while ((line = input.readLine()) != null) {
                  LOG.info("blah");
                  String[] array = line.split("\\s+");
                  if (array.length &gt; 1) {
                      processes.put(array[0], array[1]);
                  }
              }
              LOG.info("Exited while loop");
              input.close();
          }
      } catch (Exception e) {
          e.printStackTrace();
      }
      return processes;
  }
  </code></pre>
  
  <p>The program gets stuck in an infinite loop at the while condition. "blah" and "Exited while loop" never output to the log. I've ran the command in command prompt on both my win7 local machine and the server which outputs the information just fine. I've also ran the above code on my local machine which also works fine. It looks like it's some issue between Java and Windows Server 2003 that I haven't been able to find in the past 3 hours of googling. Any help would be much appreciated.</p>