From 78ac55ced8691adfa03e4efbd139897599fca7b3 Mon Sep 17 00:00:00 2001 From: Fridrich Strba Date: Tue, 23 Jun 2009 07:14:52 +0000 Subject: On Windows, when called from a console, get console output (works only with Windows XP or higher. Windows 2000 will not have console output but it will just work fine.) --- (limited to 'shell/main.c') diff --git a/shell/main.c b/shell/main.c index 2d966af..214e9c0 100644 --- a/shell/main.c +++ b/shell/main.c @@ -45,6 +45,16 @@ #endif #endif /* WITH_SMCLIENT */ +#ifdef G_OS_WIN32 +#ifdef DATADIR +#undef DATADIR +#endif +#include +#include +#define _WIN32_WINNT 0x0500 +#include +#endif + static gchar *ev_page_label; static gchar *ev_find_string; static gboolean preview_mode = FALSE; @@ -387,6 +397,31 @@ main (int argc, char *argv[]) GHashTable *args; GError *error = NULL; +#ifdef G_OS_WIN32 + + if (fileno (stdout) != -1 && + _get_osfhandle (fileno (stdout)) != -1) + { + /* stdout is fine, presumably redirected to a file or pipe */ + } + else + { + typedef BOOL (* WINAPI AttachConsole_t) (DWORD); + + AttachConsole_t p_AttachConsole = + (AttachConsole_t) GetProcAddress (GetModuleHandle ("kernel32.dll"), "AttachConsole"); + + if (p_AttachConsole != NULL && p_AttachConsole (ATTACH_PARENT_PROCESS)) + { + freopen ("CONOUT$", "w", stdout); + dup2 (fileno (stdout), 1); + freopen ("CONOUT$", "w", stderr); + dup2 (fileno (stderr), 2); + + } + } +#endif + /* Init glib threads asap */ if (!g_thread_supported ()) g_thread_init (NULL); -- cgit v0.9.1