[MLton] Non-console Windows applications and standard streams
Vesa Karvonen
vesa.a.j.k at gmail.com
Mon Mar 19 08:17:32 PST 2007
FYI, I just noticed that MLton assumes that on Windows the application is
linked as a character mode or console executable. If one specifies the
-mwindows option to the linker to create a windows application, then the
produced executable probably won't work. In particular, referring to
standard streams (even indirectly) apparently links in code that ends up
terminating the application during the evaluation of the Basis library.
Here is an example program:
val out = TextIO.openOut "test.log"
val () = TextIO.output (out, "Hello, world!")
(* If the following is commented out, the program works as one might
* expect. Otherwise the application terminates before the log file is
* created.
*)
val () = if length (CommandLine.arguments ()) = ~1
then print "Hello!\n" else ()
As I don't want my application to open a console window (at least in
production use) I use the Windows FreeConsole function to close the
console explicitly. This works for me and for now, but probably not in
all cases. A better solution might be for the Basis library to detect
when standard streams (or console) are not available.
-Vesa Karvonen
More information about the MLton
mailing list