On 7 March 2011 02:28, Trystan Spangler <[email protected]> wrote: > Announcing Silently, a package with two simple functions to run an IO action > while preventing it from writing to stdout (or the given handle)
Useful package! I tiny remark about the code: -- | Run an IO action while ignoring all output to stdout. silently :: IO a -> IO a silently = hSilently stdout -- | Run an IO action while ignoring all output to the given handle. hSilently :: Handle -> IO a -> IO a hSilently handle action = do oldHandle <- hDuplicate handle (tmpFile, tmpHandle) <- openTempFile "." "silently" hDuplicateTo tmpHandle handle finally action (hDuplicateTo oldHandle handle >> hClose tmpHandle >> removeFile tmpFile) Think about what happens if an asynchronous exception is thrown to the thread executing hSilently just after opening the temp file. It will abort the computation which causes the temp file to be left on your system and keep the tmpHandle open. You need to use bracket to ensure the temp file we always be closed and deleted. I send you a pull-request. Regards, Bas _______________________________________________ Haskell mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell
