Skip to content

W32: add std stream redirection envvar options

LRN requested to merge lrn/attachconsole into master

This commit adds two W32-only environmental variable checks:

  • G_WIN32_ALLOC_CONSOLE, if set to 1, will force glib to create a new console if the process has no console by itself. This option is for GUI apps that are launched from GUI processes, in which case there's no console anywhere near them.
  • G_WIN32_ATTACH_CONSOLE, if set to a comma-separated list of standard stream names (stdint, stdout, stderr), will reopen a given std stream and tie it to the console (using existing console or parent console). This works either with the other option (to create a console), or if the app is launched from a console process (often the case for developers). The redirection is done with freopen(), dup() and dup2(). If everything goes well, C file descriptors 0, 1 or 2 will be bound to stdin, stdout and stderr respectively (only for streams listed in the envrionmental variable), and so will be stdio streams by the same names.

With these it's possible to see the output of g_log*() functions when running GTK4 applications, which are linked as GUI applications, and thus do not get a console by default.

https://bugzilla.gnome.org/show_bug.cgi?id=790857

Fixes issue #1304 (closed)

Merge request reports