From 67b7b2f292bfb5ffdfb8e1014727e8a2507192ed Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Wed, 19 Jan 2022 15:40:58 +0100 Subject: [PATCH] Don't print to stdout during logging --- lib/GHCup/Utils/File/Posix.hs | 7 ++++--- lib/GHCup/Utils/File/Windows.hs | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/GHCup/Utils/File/Posix.hs b/lib/GHCup/Utils/File/Posix.hs index 57e03c1..ac60b3c 100644 --- a/lib/GHCup/Utils/File/Posix.hs +++ b/lib/GHCup/Utils/File/Posix.hs @@ -35,6 +35,7 @@ import Data.Sequence ( Seq, (|>) ) import Data.List import Data.Word8 import GHC.IO.Exception +import System.IO ( stderr ) import System.IO.Error import System.FilePath import System.Directory @@ -142,14 +143,14 @@ execLogged exe args chdir lfile env = do printToRegion :: Fd -> Fd -> Int -> MVar Bool -> Bool -> IO () printToRegion fileFd fdIn size pState no_color = do -- init region - forM_ [1..size] $ \_ -> BS.putStr "\n" + forM_ [1..size] $ \_ -> BS.hPut stderr "\n" void $ flip runStateT mempty $ do handle (\(ex :: SomeException) -> do ps <- liftIO $ takeMVar pState - when ps (liftIO $ BS.putStr (pos1 <> moveLineUp size <> clearScreen)) + when ps (liftIO $ BS.hPut stderr (pos1 <> moveLineUp size <> clearScreen)) throw ex ) $ readTilEOF lineAction fdIn @@ -184,7 +185,7 @@ execLogged exe args chdir lfile env = do Just (TP.Window _ w) -> do regs <- get liftIO $ forM_ (Sq.zip regs (Sq.fromList [0..(Sq.length regs - 1)])) $ \(bs, i) -> do - BS.putStr + BS.hPut stderr . overwriteNthLine (size - i) . trim w . blue diff --git a/lib/GHCup/Utils/File/Windows.hs b/lib/GHCup/Utils/File/Windows.hs index 2b5b26d..5942531 100644 --- a/lib/GHCup/Utils/File/Windows.hs +++ b/lib/GHCup/Utils/File/Windows.hs @@ -196,7 +196,8 @@ execLogged exe args chdir lfile env = do then pure () else do void $ BS.appendFile logFile some - void $ BS.hPut stdout some + -- subprocess stdout also goes to stderr for logging + void $ BS.hPut stderr some go