Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module re-exports the entirety of Pipes.Transduce.Text from the
pipes-transduce
package. It provides functions useful for treating the
stdout
and stderr
streams as text.
It is better to import it qualified:
>>>
import qualified System.Process.Streaming.Text as PT
- module Pipes.Transduce.Text
Examples
To process a standard stream as utf8 text:
>>>
execute (piped (shell "echo foo")) (foldOut (PT.asUtf8x PT.intoLazyText))
"foo\n"
asUtf8x
throws exceptions on decodign errors.
asUtf8
uses sum types instead. We must provide an
error mapping function, here we simply use id
:
>>>
executeFallibly (piped (shell "echo foo")) (foldOut (PT.asUtf8 id PT.intoLazyText))
Right "foo\n"
asFoldedLines
lets you identify and consume the lines that appear in a
stream as lazy Text
s.
>>>
:{
execute (piped (shell "{ echo foo ; echo bar ; }")) $ (foldOut (PT.asUtf8x (PT.asFoldedLines intoList))) :} ["foo","bar"]
Sometimes we want to consume the lines in stdout
and stderr
as a single
text stream. We can do this with foldOutErr
and
combinedLines
.
We also need bothAsUtf8x
to decode both streams.
>>>
:{
execute (piped (shell "{ echo ooo ; sleep 1 ; echo eee 1>&2 ; }")) $ (foldOutErr (PT.bothAsUtf8x (PT.combinedLines PT.intoLazyText))) :} "ooo\neee\n"
We can also tag each line with its provenance, using
combinedLinesPrefixing
:
>>>
:{
execute (piped (shell "{ echo ooo ; sleep 1 ; echo eee 1>&2 ; }")) $ (foldOutErr (PT.bothAsUtf8x (PT.combinedLinesPrefixing "+" "-" PT.intoLazyText))) :} "+ooo\n-eee\n"
module Pipes.Transduce.Text