<div dir="ltr">On Mon, Sep 15, 2008 at 11:39 AM, Wesley W. Terpstra <span dir="ltr">&lt;<a href="mailto:wesley@terpstra.ca">wesley@terpstra.ca</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div dir="ltr"><div class="Ih2E3d">On Sun, Sep 14, 2008 at 7:07 PM, Tom 7 <span dir="ltr">&lt;<a href="mailto:twm@andrew.cmu.edu" target="_blank">twm@andrew.cmu.edu</a>&gt;</span> wrote:<br></div><div class="gmail_quote">
<div class="Ih2E3d"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I&#39;m trying to debug a problem with using mlton+mingw+SDL on windows. Everything works fine when I run my app from the mingw command line, but when I run it from the DOS prompt or by clicking it in explorer, it terminates immediately and silently.</blockquote>

</div><div><br>I have reproduced this problem with r6841 on win2003/x64.</div></div></div></blockquote></div><br>The problem is that -mwindows removes the stdin/out/err file descriptors from the program. When you reference print, that forces the basis to create the stdOut variable. As you suspected, this does some initialization. Specifically, it checks if it&#39;s a tty, fstats it, then setmode/text&#39;s it. The fstat is failing and this gets turned into an exception that causes the program to exit. It works under msys, because msys provides *all* windows programs with stdin/out/err.<br>
<br>I discovered this using &#39;mlton -debug true&#39; and gdb. Set a breakpoint on Posix_FileSys_Stat_fstat and then trace the MLton-generated assembler. fstat fails in a &quot;dos&quot; terminal (info registers -&gt; eax = return value).<br>
<br>There are two fixes that come to mind:<br>1) handle/ignore the exception from fstat (isReg posix/io.sml:187)<br>2) setup place-holder stdin/out/err if none exist<br><br>I tend towards option #2. stdin&amp;out can come from openIn/Out &quot;NUL&quot;. However, if stderr is missing one loses exception information. Perhaps it could create a popup window. A TextPrimIO.writer that creates a window and adds text on write* calls shouldn&#39;t be that hard to implement.<br>
<br>Which do other people prefer?<br><br></div>