Safe Haskell | None |
---|---|
Language | Haskell2010 |
System.IO.Capture
- capture :: IO a -> IO (ByteString, ByteString, ByteString, Maybe ProcessStatus)
- captureStream :: IO a -> IO (ByteString IO (), ByteString IO (), ByteString IO (), ProcessID)
Documentation
capture :: IO a -> IO (ByteString, ByteString, ByteString, Maybe ProcessStatus) Source
Capture an IO action's stdout
, stderr
, and any thrown exception. Waits
for the action to complete before returning.
> (out, _, _, _) <-capture
(putStrLn
"foo") >capture
(hPutStrLn
stderr
"bar") >capture
undefined
>
captureStream :: IO a -> IO (ByteString IO (), ByteString IO (), ByteString IO (), ProcessID) Source
Stream an IO action's stdout
, stderr
, and any thrown exception. Also
returns the spawned process's pid to wait
on (otherwise the process will
become a zombie after terminating), kill, etc.
import qualified Data.ByteString.Streaming as S > let action =putStrLn
"foo" >>threadDelay
1000000 > (out, _, _, pid) <-captureStream
(replicateM_
5 action) > S.stdout
out foo foo foo foo foo >getProcessStatus
True True pid Just (Exited
ExitSuccess
)