]> www.fi.muni.cz Git - evince.git/blobdiff - previewer/ev-previewer.c
On Windows, when called from a console, get console output (works only
[evince.git] / previewer / ev-previewer.c
index afe21271a4715148e160f65fa18b8199d6d573a5..5c1980a062d4d9be484470293e8890fe69784a57 100644 (file)
 
 #include "ev-previewer-window.h"
 
+#ifdef G_OS_WIN32
+#ifdef DATADIR
+#undef DATADIR
+#endif
+#include <io.h>
+#include <conio.h>
+#define _WIN32_WINNT 0x0500
+#include <windows.h>
+#endif
+
 static gboolean      unlink_temp_file = FALSE;
 static const gchar  *print_settings;
 static const gchar **filenames;
@@ -93,6 +103,30 @@ main (gint argc, gchar **argv)
        const gchar    *filename;
        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);