silently: Prevent or capture writing to stdout and other handles.

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Warnings:

Prevent or capture writing to stdout, stderr, and other handles.


[Skip to Readme]

Properties

Versions 0.0.1, 0.0.2, 0.0.3, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5, 1.2, 1.2.0.1, 1.2.0.2, 1.2.3, 1.2.4, 1.2.4.1, 1.2.5, 1.2.5.1, 1.2.5.2, 1.2.5.3, 1.2.5.4, 1.2.5.4
Change log CHANGELOG.md
Dependencies base (>=4.3 && <5), deepseq, directory [details]
License BSD-3-Clause
Copyright (c) Trystan Spangler 2011
Author Trystan Spangler
Maintainer Simon Hengel <sol@typeful.net>, Andreas Abel
Category System, Testing
Home page https://github.com/hspec/silently
Bug tracker https://github.com/hspec/silently/issues
Source repo head: git clone https://github.com/hspec/silently
Uploaded by AndreasAbel at 2024-11-23T09:44:40Z

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for silently-1.2.5.4

[back to package description]

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: