title: Capture CMD output with AutoHotkey
body: <p>I'm trying to read Windows CMD's stdout with AutoHotkey. For example, I'd like to have the output of the <code>set</code>console command inside AHK stored in a variable. I already achieved it a while ago, which makes me all the more perplex why it's not working now.<br>
  In the AHK forums, there's a rather <a href="http://www.autohotkey.com/board/topic/3489-cmdret-return-output-from-console-progs-dll-version/" rel="nofollow">old thread</a> about <em>CMDret</em>, a DLL based functionality to do exactly what I want. The first problem was to find a working download for it, since all the links in the post were dead. Google gave me <a href="http://z4.invisionfree.com/Apps_4_Apps/ar/t7.htm" rel="nofollow">another site</a>, hosting <strong>v3.1.2</strong>. Altough there seems to be a newer one (<strong>v3.2.1</strong> respectively <strong>4d Beta</strong>), I checked it out and tested a simple example:  </p>
  
  <pre><code>msgbox % CMDret(COMSPEC " /C set")
  CMDret(CMD) 
  { 
    VarSetCapacity(StrOut, 10000) 
    RetVal := DllCall("cmdret.dll\RunReturn", "str", CMD, "str", StrOut)
    Return, %StrOut%
  }
  </code></pre>
  
  <p>Unfortunately, the MsgBox contained nothing. I then checked out <code>RetVal</code> which had a value of <strong>0</strong>; and the attached readme says: </p>
  
  <blockquote>
    <p>If the function fails, the return value is zero.</p>
  </blockquote>
  
  <p>Further down, it says:</p>
  
  <blockquote>
    <p>Note: <strong>only 32 bit</strong> console applications will currently work with the
    this dll version of CMDret (v3.1.2 or lower). Calls that require
    command.com will likely not produce any output and may crash. To avoid
    this I have included a file named "cmdstub.exe" with the download (in
    the Win9x folder). This file should be used when calling <strong>16 bit</strong>
    console applications to enable returning output.</p>
  </blockquote>
  
  <p>In conclusion, I am not sure what the problem is. My machine is running on 64 bit. But is the corresponding clause in the readme supposed to solely exclude 16 bit systems or does it rather only include 32 bit?<br>
  If the computing architecture is probably not the problem, then what could be?  </p>
  
  <p>What I am looking for is either one of the following:</p>
  
  <ol>
  <li>Can I fix the problem and keep using v3.1.2?</li>
  <li>Has anyone a working source (or even a local copy) of a newer version I could check out?</li>
  <li>Is there another approach [library, .ahk code, etc.] I could use for my purpose? (preferably similar, because CMDret seems very straightforward)</li>
  </ol>