Skip to content

Latest commit

 

History

History
51 lines (40 loc) · 1.91 KB

README.md

File metadata and controls

51 lines (40 loc) · 1.91 KB

Hackage version silently on Stackage Nightly Stackage LTS version Cabal build

silently

Silently is a package that allows you to run an IO action and prevent it from writing to stdout, or any other handle, by using silence. Or you can capture the output for yourself using capture.

For example, the program

 import System.IO.Silently

 main = do
   putStr "putStrLn: " >> putStrLn "puppies!"
   putStr "silenced: " >> silence (putStrLn "kittens!")
   putStrLn ""
   (captured, result) <- capture (putStr "wookies!" >> return 123)
   putStr "captured: " >> putStrLn captured
   putStr "returned: " >> putStrLn (show result)

will print:

 putStrLn: puppies!
 silenced:
 captured: wookies!
 returned: 123

Not thread-safe

Since all threads of a process share the standard output handles stdout and stderr, capturing output to these handle will capture the output of all threads, not just the one running the action under capture.

In essence, this library does not work in a situation where multiple threads are writing to the handle whose output produced by the given action we want to capture.

See:

Further limitations

Capturing/silencing might not work as expected if the action uses the FFI or conceals output under unsafePerformIO or similar unsafe operations.

Examples: