title: Running Windows Command in Java Using Runtime.getRuntime().exec(String[])
body: <p>I'm having a little bit of trouble running this confusing windows command from java and I can't find anything that is similar to what I'm trying to do to base my code against.</p>
  
  <p>Basically the windows command kills any PIDs relating to sockets with a CLOSE_WAIT status and related to the specific ip:port specified. My issue is I'm having a hard time getting it to run using Runtime.getRuntime().exec().</p>
  
  <pre><code>String[] command = {"cmd /c for /f \"tokens=5\" %a in ('netstat -noa -p tcp ^| find /i \"CLOSE_WAIT\" ^| find /i \""+ip+":443\" ') do if not \"%a\"==\"0\" echo taskkill /pid %a"};     
  Process runCommand = Runtime.getRuntime().exec(command);
  runCommand.waitFor(); 
  </code></pre>
  
  <p>While doing this I am current getting the error message: </p>
  
  <blockquote>
    <p>class java.io.IOException  Message: Cannot run program "C:/ cmd /c for
    /f "tokens=5" %a in ('netstat -noa -p tcp ^| find /i "CLOSE_WAIT" ^|
    find /i "ip:443" ') do if not "%a"=="0" echo taskkill /pid %a":
    CreateProcess error=2, The system cannot find the file specified</p>
  </blockquote>
  
  <p>Any help would be much appreciated. Thanks!</p>