title: WinDbg: using commands for the condition in .if
body: <p>WinDbg has the .if statement for conditional execution of commands:</p>
  
  <pre><code>   .if (Condition) { Commands } .else { Commands } 
  </code></pre>
  
  <p>For Condition, it's not possible to use WinDbg commands. Is there any indirect way of using commands for the condition, e.g. through pseudo registers?</p>
  
  <p>Example task to accomplish:
  If a logfile is already opened, do nothing. If no logfile is open, use <em>.logopen /t /u /d</em></p>
  
  <p>With <em>.logfile</em>, I can find out whether  a log is open or not. But how to parse that output and how to assign the result to a pseudo register?</p>
  
  <p>Any other way without pseudo registers is also welcome.</p>
  
  <p>As the example may not seem very useful, consider the following tasks which can be automated by scripting or the .cmdtree window:</p>
  
  <ul>
  <li>Loading the correct version of SOS, e.g. <code>.if (lm m clr == clr) { .loadby sos clr } .elseif (lm m mscorwks == mscorwks) {.loadby sos mscorwks}</code></li>
  <li>Things I always forget to do, e.g. <code>.if (| == myprocess) {.childdbg 1; .sympath+ mydir}</code></li>
  </ul>