title: wait for process to end in windows batch file
body: <p>I would like to write a windows script that waits until a given process (PID) has ended before executing something. So far I have (PID=1234):</p>
  
  <pre><code>:loop
  set VAR="tasklist | find /i " 1234 " /c"
  if NOT (' %VAR% ')=="0" goto loop
  **do something**
  </code></pre>
  
  <p>but already the line</p>
  
  <pre><code>set VAR="tasklist | find /i " 1234 " /c"
  </code></pre>
  
  <p>doesn't work, it stores the string instead of the evaluation. Or maybe it's supposed to? In which case the line</p>
  
  <pre><code>if NOT (' %VAR% ')=="0" goto loop
  </code></pre>
  
  <p>should evaluate the contents of VAR, but if I type this manually in a console I just get </p>
  
  <pre><code>"tasklist | find /i " was unexpected
  </code></pre>
  
  <p>I understand the double quotes in</p>
  
  <pre><code>set VAR="tasklist | find /i " 1234 " /c"
  </code></pre>
  
  <p>are problematic but I need a space on each side of the PID (1234 in the example) to ensure that it is not a substring of another process (like 12345) for it to work properly.</p>
  
  <p>Any DOS experts out there?</p>