Commit 76fb4b7e authored by pcapriotti's avatar pcapriotti
Browse files

Ignore broken pipe error in readProcessWithExitCode (#4889)

parent 38172337
......@@ -91,7 +91,7 @@ import System.Exit ( ExitCode(..) )
#ifdef __GLASGOW_HASKELL__
#if __GLASGOW_HASKELL__ >= 611
import GHC.IO.Exception ( ioException, IOErrorType(..) )
import GHC.IO.Exception ( ioException, IOErrorType(..), IOException(..) )
#else
import GHC.IOBase ( ioException, IOErrorType(..) )
#endif
......@@ -449,8 +449,21 @@ readProcessWithExitCode cmd args input =
waitErr <- forkWait $ C.evaluate $ rnf err
-- now write and flush any input
when (not (null input)) $ do hPutStr inh input; hFlush inh
hClose inh -- done with stdin
let writeInput = do
unless (null input) $ do
hPutStr inh input
hFlush inh
hClose inh
#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 611
C.catch writeInput $ \e -> case e of
IOError { ioe_type = ResourceVanished
, ioe_errno = Just ioe }
| Errno ioe == ePIPE -> return ()
_ -> throwIO e
#else
writeInput
#endif
-- wait on the output
waitOut
......
module Main where
import System.Process
main :: IO ()
main = do
let text = unlines . map show $ [1..10000 :: Int]
(code, out, _) <- readProcessWithExitCode "head" ["-n", "1"] text
print code
putStr out
......@@ -29,3 +29,4 @@ test('4198',
[''])
test('3994', only_ways(['threaded1','threaded2']), compile_and_run, [''])
test('T4889', normal, compile_and_run, [''])
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment