io-capture-0.2: capture IO action's stdout and stderr




As usual, You specify import only this function.

capture :: IO a -> String -> IO (String, String)Source

Takes an IO as action to run, and a String as given stdin, then returns whole stdout and stderr as String of tuple.

 import System.IO.Capture (capture)

 main = print =<< capture (getLine >>= putStr) "foobar"
   -- prints ("foobar","")

WARNING: If Lazy Reading such as getContents was contained in the action, its behavior is very strange. For detail, see tests/Tests.hs.

If you want to use lazy reading in the action, I recomend you use these.