diff --git a/Distribution/Simple/Utils.hs b/Distribution/Simple/Utils.hs index 84343e8b6846b3f254ed3422a429b89bbccb260c..33ef40bd78af6ead1b8ef15488ed03b13232bfca 100644 --- a/Distribution/Simple/Utils.hs +++ b/Distribution/Simple/Utils.hs @@ -259,7 +259,11 @@ rawSystemStdout' verbosity path args = do -- fork off a thread to pull on (and discard) the stderr -- so if the process writes to stderr we do not block. - forkIO $ hGetContents errh >>= evaluate . length >> return () + -- NB. do the hGetContents synchronously, otherwise the outer + -- bracket can exit before this thread has run, and hGetContents + -- will fail. + err <- hGetContents errh + forkIO $ do evaluate (length err); return () -- wait for all the output output <- hGetContents outh