Why does writing to STD_OUTPUT_HANDLE crash under Sublime Text?
<p>I have an application which happens to log to the console using winapi's WriteFile on a handle acquired from GetStdHandle. Minimal test case:</p>

<pre><code>#include &lt;Windows.h&gt;

int main(int argc, char** argv) {
  HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
  if(GetFileType(console) == FILE_TYPE_UNKNOWN)
    return;
  WriteFile(console, "abc", 3, 0, 0);
}
</code></pre>

<p>built with default options in VS2013. This works without problems when invoked on a standard Windows console and when invoked from python2/python3/Sublime's console using e.g. <code>subprocess.Popen('/path/to/my.exe')</code>.</p>

<p>Now I want to run this program as a build system in SublimeText 3. This is the build definition:</p>

<pre><code>{
  "cmd": [ "/path/to/my.exe" ]
}
</code></pre>

<p>According to <a href="http://docs.sublimetext.info/en/latest/reference/build_systems/exec.html" rel="nofollow noreferrer">documentation</a> this should sort of be equivalent to using subprocess.Popen. However when I invoke this 'build system' Sublime's output pane displays <code>abc</code> and then the call to WriteFile crashes with</p>

<pre><code>0xC0000005: Access violation writing location 0x00000000.
</code></pre>

<p>What happens here? Is this a problem in my code, in Sublime, or in WriteFile? Anything that can be done about it? (I tried using <code>shell_cmd</code> instead of <code>cmd</code> but that makes no difference)</p>