Skip to content
/ silently Public

Prevent or capture output to stdout or other handles in Haskell

License

Notifications You must be signed in to change notification settings

hspec/silently

Repository files navigation

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

Limitations

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

Examples:

About

Prevent or capture output to stdout or other handles in Haskell

Resources

License

Stars

Watchers

Forks

Packages

No packages published