@@ -7,6 +7,7 @@ import Control.Concurrent
77import Control.Concurrent.MVar
88import Control.Monad (unless )
99import Control.Arrow ((>>>) )
10+ import qualified GHC.IO.Exception
1011
1112import qualified Data.ByteString as BS
1213import qualified Data.ByteString.Lazy as BSL
@@ -373,40 +374,42 @@ ghciThreads = unsafePerformIO $ newMVar []
373374-- System
374375
375376bash :: String -> IO String
376- bash command =
377- c_ " bash" [" -c" , command] " "
377+ bash command = do
378+ (exit, stdOut, stdErr) <- c_ " bash" [" -c" , command] " "
379+ pure $ show $ stdErr <> stdOut
378380
379381bashq :: String -> IO String
380- bashq command =
381- cq_ " bash" [" -c" , command] " "
382+ bashq command = do
383+ (exit, stdOut, stdErr) <- cq_ " bash" [" -c" , command] " "
384+ pure $ show $ stdErr <> stdOut
382385
383386
384- c_ :: String -> [String ] -> String -> IO String
387+ -- Call executable and print output in debug mode
388+ c_ :: String -> [String ] -> String -> IO (GHC.IO.Exception. ExitCode , String , String )
385389c_ bin args input = do
386390 atomicPutStrLnDebug $ " 🤖 " <> bin <> " " <> show args <> " " <> input
387391 (exit, stdOut, stdErr) <- System.Process. readProcessWithExitCode bin args input
388- res <-
389- if Prelude. length stdErr > 0
390- then pure stdErr
391- else pure stdOut
392392 -- This doesn't quite work for debugging because bash will honour the sequence codes of the output
393393 -- which gives us confusing results. I.e. Elm compilation clears the buffer during operation
394394 -- onlyWhen (Prelude.length stdErr > 0) $ atomicPutStrLnDebug $ "└── stdErr: " <> stdErr
395395 -- onlyWhen (Prelude.length stdOut > 0) $ atomicPutStrLnDebug $ "└── stdOut: " <> stdOut
396396 -- This doesn't happen with the show instance as it escapes sequences inside the string
397397 atomicPutStrLnDebug $ " └── " <> show (exit, stdOut, stdErr)
398- pure $ show (exit, stdOut, stdErr)
398+ pure $ (exit, stdOut, stdErr)
399399
400400
401- cq_ :: String -> [String ] -> String -> IO String
401+ -- Call quiet, don't print output in debug mode
402+ cq_ :: String -> [String ] -> String -> IO (GHC.IO.Exception. ExitCode , String , String )
402403cq_ bin args input = do
403404 atomicPutStrLnDebug $ " 🤖 " <> bin <> " " <> show args <> " " <> input
404405 (exit, stdOut, stdErr) <- System.Process. readProcessWithExitCode bin args input
405- res <-
406- if Prelude. length stdErr > 0
407- then pure stdErr
408- else pure stdOut
409- pure $ show (exit, stdOut, stdErr)
406+ pure $ (exit, stdOut, stdErr)
407+
408+
409+ execCombineStdOutErr :: String -> [String ] -> String -> IO String
410+ execCombineStdOutErr bin args input = do
411+ (exit, stdOut, stdErr) <- c_ bin args input
412+ pure $ stdErr <> stdOut
410413
411414
412415requireBinary :: String -> IO FilePath
0 commit comments