-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Streaming interface to system processes. -- @package process-streaming @version 0.5.0.1 -- | Lenses and traversals for CreateProcess and related types. module System.Process.Lens -- |
--   _cmdspec :: Lens' CreateProcess CmdSpec 
--   
_cmdspec :: Functor f => (CmdSpec -> f CmdSpec) -> CreateProcess -> f CreateProcess -- |
--   _ShellCommand :: Prism' CmdSpec String
--   
_ShellCommand :: Applicative m => (String -> m String) -> CmdSpec -> m CmdSpec -- |
--   _RawCommand :: Prism' CmdSpec (FilePath,[String])
--   
_RawCommand :: Applicative m => ((FilePath, [String]) -> m (FilePath, [String])) -> CmdSpec -> m CmdSpec -- |
--   _cwd :: Lens' CreateProcess (Maybe FilePath)
--   
_cwd :: Functor f => (Maybe FilePath -> f (Maybe FilePath)) -> CreateProcess -> f CreateProcess -- |
--   _env :: Lens' CreateProcess (Maybe [(String,String)])
--   
_env :: Functor f => (Maybe [(String, String)] -> f (Maybe [(String, String)])) -> CreateProcess -> f CreateProcess -- | A lens for the (std_in,std_out,std_err) triplet. -- --
--   streams :: Lens' CreateProcess (StdStream,StdStream,StdStream)
--   
streams :: Functor f => ((StdStream, StdStream, StdStream) -> f (StdStream, StdStream, StdStream)) -> CreateProcess -> f CreateProcess _close_fds :: Functor f => (Bool -> f Bool) -> CreateProcess -> f CreateProcess _create_group :: Functor f => (Bool -> f Bool) -> CreateProcess -> f CreateProcess _delegate_ctlc :: Functor f => (Bool -> f Bool) -> CreateProcess -> f CreateProcess -- | A Lens for the return value of createProcess that -- focuses on the handles. -- --
--   handles :: Lens' (Maybe Handle, Maybe Handle, Maybe Handle,ProcessHandle) (Maybe Handle, Maybe Handle, Maybe Handle)
--   
handles :: Functor m => ((Maybe Handle, Maybe Handle, Maybe Handle) -> m (Maybe Handle, Maybe Handle, Maybe Handle)) -> (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) -> m (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) -- | A Prism that matches when none of the standard streams have -- been piped. -- --
--   nohandles :: Prism' (Maybe Handle, Maybe Handle, Maybe Handle) ()
--   
nohandles :: Applicative m => (() -> m ()) -> (Maybe Handle, Maybe Handle, Maybe Handle) -> m (Maybe Handle, Maybe Handle, Maybe Handle) -- | A Prism that matches when only stdout has been -- piped. -- --
--   handleso :: Prism' (Maybe Handle, Maybe Handle, Maybe Handle) (Handle)
--   
handleso :: Applicative m => (Handle -> m Handle) -> (Maybe Handle, Maybe Handle, Maybe Handle) -> m (Maybe Handle, Maybe Handle, Maybe Handle) -- | A Prism that matches when only stderr has been -- piped. -- --
--   handlese :: Prism' (Maybe Handle, Maybe Handle, Maybe Handle) (Handle)
--   
handlese :: Applicative m => (Handle -> m Handle) -> (Maybe Handle, Maybe Handle, Maybe Handle) -> m (Maybe Handle, Maybe Handle, Maybe Handle) -- | A Prism that matches when only stdout and -- stderr have been piped. -- --
--   handlesoe :: Prism' (Maybe Handle, Maybe Handle, Maybe Handle) (Handle, Handle)
--   
handlesoe :: Applicative m => ((Handle, Handle) -> m (Handle, Handle)) -> (Maybe Handle, Maybe Handle, Maybe Handle) -> m (Maybe Handle, Maybe Handle, Maybe Handle) -- | A Prism that matches when only stdin has been piped. -- --
--   handlesi :: Prism' (Maybe Handle, Maybe Handle, Maybe Handle) (Handle)
--   
handlesi :: Applicative m => (Handle -> m Handle) -> (Maybe Handle, Maybe Handle, Maybe Handle) -> m (Maybe Handle, Maybe Handle, Maybe Handle) handlesio :: Applicative m => ((Handle, Handle) -> m (Handle, Handle)) -> (Maybe Handle, Maybe Handle, Maybe Handle) -> m (Maybe Handle, Maybe Handle, Maybe Handle) handlesie :: Applicative m => ((Handle, Handle) -> m (Handle, Handle)) -> (Maybe Handle, Maybe Handle, Maybe Handle) -> m (Maybe Handle, Maybe Handle, Maybe Handle) -- | A Prism that matches when all three stdin, -- stdout and stderr have been piped. -- --
--   handlesioe :: Prism' (Maybe Handle, Maybe Handle, Maybe Handle) (Handle, Handle, Handle)
--   
handlesioe :: Applicative m => ((Handle, Handle, Handle) -> m (Handle, Handle, Handle)) -> (Maybe Handle, Maybe Handle, Maybe Handle) -> m (Maybe Handle, Maybe Handle, Maybe Handle) -- | This module contains helper functions and types built on top of -- System.Process and Pipes. -- -- They provide concurrent, streaming access to the inputs and outputs of -- system processes. -- -- Error conditions that are not directly related to IO are made explicit -- in the types. -- -- Regular Consumers, Parsers from pipes-parse and -- folds from Pipes.Prelude (also folds from -- pipes-bytestring and pipes-text) can be used to -- consume the output streams of the external processes. module System.Process.Streaming execute :: PipingPolicy Void a -> CreateProcess -> IO (ExitCode, a) -- | Executes an external process. The standard streams are piped and -- consumed in a way defined by the PipingPolicy argument. -- -- This fuction re-throws any IOExceptions it encounters. -- -- If the consumption of the standard streams fails with e, the -- whole computation is immediately aborted and e is returned. -- (An exception is not thrown in this case.). -- -- If an error e or an exception happens, the external process -- is terminated. executeFallibly :: PipingPolicy e a -> CreateProcess -> IO (Either e (ExitCode, a)) -- | A PipingPolicy determines what standard streams will be piped -- and what to do with them. -- -- The user doesn't need to manually set the std_in, -- std_out and std_err fields of the CreateProcess -- record to CreatePipe, this is done automatically. -- -- A PipingPolicy is parametrized by the type e of errors -- that can abort the processing of the streams. data PipingPolicy e a -- | Do not pipe any standard stream. nopiping :: PipingPolicy e () -- | Pipe stdout. pipeo :: (Show e, Typeable e) => Siphon ByteString e a -> PipingPolicy e a -- | Pipe stderr. pipee :: (Show e, Typeable e) => Siphon ByteString e a -> PipingPolicy e a -- | Pipe stdout and stderr. pipeoe :: (Show e, Typeable e) => Siphon ByteString e a -> Siphon ByteString e b -> PipingPolicy e (a, b) -- | Pipe stdout and stderr and consume them combined as -- Text. pipeoec :: (Show e, Typeable e) => LinePolicy e -> LinePolicy e -> Siphon Text e a -> PipingPolicy e a -- | Pipe stdin. pipei :: (Show e, Typeable e) => Pump ByteString e i -> PipingPolicy e i -- | Pipe stdin and stdout. pipeio :: (Show e, Typeable e) => Pump ByteString e i -> Siphon ByteString e a -> PipingPolicy e (i, a) -- | Pipe stdin and stderr. pipeie :: (Show e, Typeable e) => Pump ByteString e i -> Siphon ByteString e a -> PipingPolicy e (i, a) -- | Pipe stdin, stdout and stderr. pipeioe :: (Show e, Typeable e) => Pump ByteString e i -> Siphon ByteString e a -> Siphon ByteString e b -> PipingPolicy e (i, a, b) -- | Pipe stdin, stdout and stderr, consuming -- the last two combined as Text. pipeioec :: (Show e, Typeable e) => Pump ByteString e i -> LinePolicy e -> LinePolicy e -> Siphon Text e a -> PipingPolicy e (i, a) newtype Pump b e a Pump :: (Consumer b IO () -> IO (Either e a)) -> Pump b e a runPump :: Pump b e a -> Consumer b IO () -> IO (Either e a) fromProducer :: Producer b IO r -> Pump b e () fromSafeProducer :: Producer b (SafeT IO) r -> Pump b e () fromFallibleProducer :: Producer b (ExceptT e IO) r -> Pump b e () -- | A Siphon represents a computation that completely drains a -- producer, but may fail early with an error of type e. -- -- pure creates a Siphon that does nothing besides draining -- the Producer. -- -- <*> executes its arguments concurrently. The -- Producer is forked so that each argument receives its own copy -- of the data. data Siphon b e a -- | Builds a Siphon out of a computation that does something with a -- Producer, but may fail with an error of type e. -- -- Even if the original computation doesn't completely drain the -- Producer, the constructed Siphon will. siphon :: (Producer b IO () -> IO (Either e a)) -> Siphon b e a -- | Builds a Siphon out of a computation that drains a -- Producer completely, but may fail with an error of type -- e. siphon' :: (forall r. Producer b IO r -> IO (Either e (a, r))) -> Siphon b e a fromFold :: (Producer b IO () -> IO a) -> Siphon b e a -- | Builds a Siphon out of a computation that folds a -- Producer and drains it completely. fromFold' :: (forall r. Producer b IO r -> IO (a, r)) -> Siphon b e a fromFold'_ :: (forall r. Producer b IO r -> IO r) -> Siphon b e () fromConsumer :: Consumer b IO r -> Siphon b e () fromSafeConsumer :: Consumer b (SafeT IO) r -> Siphon b e () fromFallibleConsumer :: Consumer b (ExceptT e IO) r -> Siphon b e () -- | Turn a Parser from pipes-parse into a Sihpon. fromParser :: Parser b IO (Either e a) -> Siphon b e a -- | Constructs a Siphon that aborts the computation if the -- underlying Producer produces anything. unwanted :: a -> Siphon b b a -- | See the section Non-lens decoding functions in the -- documentation for the pipes-text package. type DecodingFunction bytes text = forall r. Producer bytes IO r -> Producer text IO (Producer bytes IO r) -- | Constructs a Siphon that works on encoded values out of a -- Siphon that works on decoded values. -- -- The two first arguments are a decoding function and a Siphon -- that determines how to handle leftovers. Pass pure id to -- ignore leftovers. Pass unwanted id to abort the computation -- if leftovers remain. encoded :: (Show e, Typeable e) => DecodingFunction bytes text -> Siphon bytes e (a -> b) -> Siphon text e a -> Siphon bytes e b -- | Defines how to decode a stream of bytes into text, including what to -- do in presence of leftovers. Also defines how to manipulate each -- individual line of text. data LinePolicy e -- | Constructs a LinePolicy. -- -- The second argument is a Siphon value that specifies how to -- handle decoding failures. Passing pure () will ignore any -- leftovers. Passing unwanted () will abort the computation if -- leftovers remain. -- -- The third argument is a function that modifies each individual line. -- The line is represented as a Producer to avoid having to keep -- it wholly in memory. If you want the lines unmodified, just pass -- id. Line prefixes are easy to add using applicative notation: -- --
--   (\x -> yield "prefix: " *> x)
--   
linePolicy :: (Show e, Typeable e) => DecodingFunction ByteString Text -> Siphon ByteString e () -> (forall r. Producer Text IO r -> Producer Text IO r) -> LinePolicy e executePipeline :: PipingPolicy Void a -> CreatePipeline Void -> IO a -- | Similar to executeFallibly, but instead of a single process it -- executes a (possibly branching) pipeline of external processes. -- -- The PipingPolicy argument views the pipeline as a synthetic -- process for which stdin is the stdin of the first -- stage, stdout is the stdout of the leftmost terminal -- stage among those closer to the root, and stderr is a -- combination of the stderr streams of all the stages. -- -- The combined stderr stream always has UTF-8 encoding. -- -- This function has a limitation compared to the standard UNIX -- pipelines. If a downstream process terminates early without error, the -- upstream processes are not notified and keep going. There is no -- SIGPIPE-like functionality, in other words. executePipelineFallibly :: (Show e, Typeable e) => PipingPolicy e a -> CreatePipeline e -> IO (Either e a) data CreatePipeline e CreatePipeline :: (Stage e) -> (NonEmpty (Tree (SubsequentStage e))) -> CreatePipeline e -- | Builds a (possibly branching) pipeline assuming that stderr -- has the same encoding in all the stages, that no computation is -- perfored between the stages, and that any exit code besides -- ExitSuccess in a stage actually represents an error. simplePipeline :: DecodingFunction ByteString Text -> CreateProcess -> NonEmpty (Tree (CreateProcess)) -> CreatePipeline String -- | An individual stage in a process pipeline. -- -- The LinePolicy field defines how to handle stderr when -- stderr is piped. -- -- Also required is a function that determines if the returned exit code -- represents an error or not. This is necessary because some programs -- use non-standard exit codes. data Stage e Stage :: CreateProcess -> LinePolicy e -> (Int -> Maybe e) -> Stage e processDefinition :: Stage e -> CreateProcess stderrLinePolicy :: Stage e -> LinePolicy e exitCodePolicy :: Stage e -> Int -> Maybe e -- | Any stage beyond the first in a process pipeline. -- -- Incoming data is passed through the Pipe before being fed to -- the process. -- -- Use cat (the identity Pipe from Pipes) if no -- pre-processing is required. data SubsequentStage e SubsequentStage :: (forall a. Pipe ByteString ByteString (ExceptT e IO) a) -> (Stage e) -> SubsequentStage e instance Typeable WrappedError instance Functor (PipingPolicy e) instance Show e => Show (WrappedError e) instance Functor (Siphon b e) instance Functor Stage instance Functor CreatePipeline instance Functor SubsequentStage instance (Show e, Typeable e, Monoid a) => Monoid (Siphon b e a) instance (Show e, Typeable e) => Applicative (Siphon b e) instance Bifunctor (Siphon b) instance (Show e, Typeable e, Monoid a) => Monoid (Pump b e a) instance (Show e, Typeable e) => Applicative (Pump b e) instance Bifunctor (Pump b) instance Functor (Pump b e) instance (Show e, Typeable e, Monoid a) => Monoid (Conceit e a) instance (Show e, Typeable e) => Alternative (Conceit e) instance (Show e, Typeable e) => Applicative (Conceit e) instance Bifunctor Conceit instance Functor (Conceit e) instance (Show e, Typeable e) => Exception (WrappedError e) instance Functor LinePolicy instance Bifunctor PipingPolicy