writing to stdout in an windows app without a console

Simon Marlow simonmar at microsoft.com
Wed Feb 16 09:49:35 EST 2005


On 16 February 2005 14:06, Duncan Coutts wrote:

> On Wed, 2005-02-16 at 14:31 +0200, Krasimir Angelov wrote:
>> On Wed, 16 Feb 2005 12:01:06 +0000, Duncan Coutts
>> <duncan.coutts at worc.ox.ac.uk> wrote:
>>> What's your opinion of making writing to stdout fail without
>>> raising an exception when the application is compiled with
>>> --subsystem 
>>> windows?
>> 
>> I think the current behaviour is the right one. After all we don't
>> have valid stdout/stdin and I don't see any reason to hide this.
> 
> True, but it's not the behaviour that other windows programming
> systems implement:
> 
> For example MS's C library happily ignores output to stdout:
> 
> #include <stdio.h>
> 
> int main () {
>   int res_code = fprintf(stdout, "hello world!\n");
>   fprintf(stderr, "res_code = %d\n", res_code);
> 
>   return 0;
> }
> 
> now compiling with mingw's gcc:
> gcc testio.c -Xlinker --subsystem -Xlinker windows
> 
> and from a windows console (ie not a msys / cygwin window)
> 
> a.exe 2> err
> 
> then saying "type err" gives us the output:
> res_code = 13

I've seen this behaviour vary between versions of Windows (maybe even
between versions of msvcrt, MS's C library).  A strange experience we
had with the Visual Studio extension was that I was initially just doing
output to stderr from the DLL for debugging, which worked fine on my
machine but crashed on other people's machines.  We had to remove all
uses of stdout/stderr from the Haskell DLL (including the runtime!) to
get it going reliably.

Cheers,
	Simon


More information about the Glasgow-haskell-users mailing list