Created
February 20, 2017 18:28
-
-
Save expipiplus1/eabcd32d05255d7878f5c0c47c2f778d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main | |
( main | |
) where | |
import GHC.IO.Exception | |
import System.IO | |
import System.IO.Error | |
import System.Process.Typed | |
main :: IO () | |
main = | |
let pc = setStdin createPipe | |
$ proc "ghc" ["-e", "System.IO.hClose System.IO.stdin"] | |
in withProcess pc $ \p -> do | |
let inn = getStdin p | |
-- wait for the pipe to be closed | |
_ <- waitExitCode p | |
-- Use the pipe | |
hPutStrLn inn "hello" | |
-- Uncomment this to make things work | |
-- handleResourceVanished (hClose inn) | |
pure () | |
handleResourceVanished :: IO a -> IO (Maybe a) | |
handleResourceVanished a = | |
(Just <$> a) `catchIOError` | |
(\e -> | |
if ioeGetErrorType e == ResourceVanished | |
then pure Nothing | |
else ioError e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment