writing to stdout in an windows app without a console

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Wed Feb 16 09:05:47 EST 2005

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

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

which is the number of characters output. Upon an error it would have
been negative (according to the fprintf man page).

As I said before I don't know which part of the windows stack implements
this behaviour (papering over the fact there is no stdout handle) but it
is apparently standard behaviour.


More information about the Glasgow-haskell-users mailing list