[project @ 2005-07-11 10:25:43 by simonmar]
authorsimonmar <unknown>
Mon, 11 Jul 2005 10:25:43 +0000 (10:25 +0000)
committersimonmar <unknown>
Mon, 11 Jul 2005 10:25:43 +0000 (10:25 +0000)
mingw32: ignore isDoesNotExistError failure from
GHC.ConsoleHandler.flushConsole

Submitted-by: Brian Smith <brianlsmith at gmail.com>

ghc/compiler/ghci/InteractiveUI.hs

index 174317e..7cd720c 100644 (file)
@@ -199,9 +199,13 @@ interactiveUI session srcs maybe_expr = do
 #if defined(mingw32_HOST_OS)
     -- The win32 Console API mutates the first character of 
     -- type-ahead when reading from it in a non-buffered manner. Work
-    -- around this by flushing the input buffer of type-ahead characters.
-    -- 
-   GHC.ConsoleHandler.flushConsole stdin
+    -- around this by flushing the input buffer of type-ahead characters,
+    -- but only if stdin is available.
+   flushed <- IO.try (GHC.ConsoleHandler.flushConsole stdin)
+   case flushed of 
+       Left err | isDoesNotExistError err -> return ()
+                | otherwise -> ioError err
+       Right () -> return ()
 #endif
    startGHCi (runGHCi srcs maybe_expr)
        GHCiState{ progname = "<interactive>",