Index: /trunk/source/lisp-kernel/lisp-debug.c
===================================================================
--- /trunk/source/lisp-kernel/lisp-debug.c	(revision 12767)
+++ /trunk/source/lisp-kernel/lisp-debug.c	(revision 12768)
@@ -111,4 +111,46 @@
   stdIn = GetStdHandle(STD_INPUT_HANDLE);
   return (stdIn == NULL);
+}
+#endif
+
+
+#ifdef WINDOWS
+Boolean first_debugger_call = TRUE;
+
+void
+setup_debugger_streams()
+{
+  HANDLE h;
+  int fd;
+  FILE *f;
+
+  if (first_debugger_call) {
+    first_debugger_call = FALSE;
+    if (stdin_is_dev_null())
+      AllocConsole();
+    // Reassociate C's stdin with Windows' stdin
+    h = GetStdHandle(STD_INPUT_HANDLE);
+    fd = _open_osfhandle((intptr_t)h, _O_TEXT);
+    if (fd >= 0) {
+      f = _fdopen(fd, "r");
+      *stdin = *f;
+    }
+    // Reassociate C's stdout with Windows' stdout
+    h = GetStdHandle(STD_OUTPUT_HANDLE);
+    fd = _open_osfhandle((intptr_t)h, _O_TEXT);
+    if (fd >= 0) {
+      f = _fdopen(fd, "w");
+      *stdout = *f;
+    }
+    // Reassociate C's stderr with Windows' stderr
+    h = GetStdHandle(STD_ERROR_HANDLE);
+    fd = _open_osfhandle((intptr_t)h, _O_TEXT);
+    if (fd >= 0) {
+      f = _fdopen(fd, "w");
+      *stderr = *f;
+    }
+    dbgout = stderr;
+  }
+  return;
 }
 #endif
@@ -708,4 +750,8 @@
 {
 
+#ifdef WINDOWS
+  setup_debugger_streams();
+#endif
+
 #ifdef PPC
 #ifdef PPC64
@@ -1122,8 +1168,4 @@
 #endif
 
-#ifdef WINDOWS
-Boolean first_debugger_call = TRUE;
-#endif
-
 
 OSStatus
@@ -1139,35 +1181,5 @@
 
 #ifdef WINDOWS
-  HANDLE h;
-  int fd;
-  FILE *f;
-
-  if (first_debugger_call) {
-    first_debugger_call = FALSE;
-    if (stdin_is_dev_null())
-      AllocConsole();
-    // Reassociate C's stdin with Windows' stdin
-    h = GetStdHandle(STD_INPUT_HANDLE);
-    fd = _open_osfhandle((intptr_t)h, _O_TEXT);
-    if (fd >= 0) {
-      f = _fdopen(fd, "r");
-      *stdin = *f;
-    }
-    // Reassociate C's stdout with Windows' stdout
-    h = GetStdHandle(STD_OUTPUT_HANDLE);
-    fd = _open_osfhandle((intptr_t)h, _O_TEXT);
-    if (fd >= 0) {
-      f = _fdopen(fd, "w");
-      *stdout = *f;
-    }
-    // Reassociate C's stderr with Windows' stderr
-    h = GetStdHandle(STD_ERROR_HANDLE);
-    fd = _open_osfhandle((intptr_t)h, _O_TEXT);
-    if (fd >= 0) {
-      f = _fdopen(fd, "w");
-      *stderr = *f;
-    }
-    dbgout = stderr;
-  }
+  setup_debugger_streams();
 #endif
 
@@ -1225,4 +1237,5 @@
     fprintf(dbgout, "[%d] Clozure CL kernel debugger: ", main_thread_pid);
 #endif
+    fflush(dbgout);
     state = apply_debug_command(xp, readc(), info, why);
   }
