-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Streaming interface to system processes. -- -- Concurrent, streaming access to the input and outputs of system -- processes. @package process-streaming @version 0.9.2 -- | Lenses and traversals for CreateProcess and related types. -- -- These are provided as a convenience and aren't at all required to use -- the other modules of this package. -- -- For basic lens functionality with few dependencies, the -- microlens package is a good option. module System.Process.Lens -- |
-- _cmdspec :: Lens' CreateProcess CmdSpec --_cmdspec :: forall f. Functor f => (CmdSpec -> f CmdSpec) -> CreateProcess -> f CreateProcess -- |
-- _ShellCommand :: Traversal' CmdSpec String --_ShellCommand :: forall m. Applicative m => (String -> m String) -> CmdSpec -> m CmdSpec -- |
-- _RawCommand :: Traversal' CmdSpec (FilePath,[String]) --_RawCommand :: forall m. Applicative m => ((FilePath, [String]) -> m (FilePath, [String])) -> CmdSpec -> m CmdSpec -- |
-- _cwd :: Lens' CreateProcess (Maybe FilePath) --_cwd :: forall f. Functor f => (Maybe FilePath -> f (Maybe FilePath)) -> CreateProcess -> f CreateProcess -- |
-- _env :: Lens' CreateProcess (Maybe [(String,String)]) --_env :: forall f. Functor f => (Maybe [(String, String)] -> f (Maybe [(String, String)])) -> CreateProcess -> f CreateProcess -- | An improper lens to get and insert values in an association list. It -- assumes that there are no duplicate keys in the list. envAt :: (Eq k, Applicative f) => k -> (Maybe v -> f (Maybe v)) -> ([(k, v)] -> f [(k, v)]) -- | A lens for the (std_in,std_out,std_err) triplet. -- --
-- std_streams :: Lens' CreateProcess (StdStream,StdStream,StdStream) --std_streams :: forall f. Functor f => ((StdStream, StdStream, StdStream) -> f (StdStream, StdStream, StdStream)) -> CreateProcess -> f CreateProcess _std_in :: forall f. Functor f => (StdStream -> f (StdStream)) -> CreateProcess -> f CreateProcess _std_out :: forall f. Functor f => (StdStream -> f (StdStream)) -> CreateProcess -> f CreateProcess _std_err :: forall f. Functor f => (StdStream -> f (StdStream)) -> CreateProcess -> f CreateProcess _close_fds :: forall f. Functor f => (Bool -> f Bool) -> CreateProcess -> f CreateProcess _create_group :: forall f. Functor f => (Bool -> f Bool) -> CreateProcess -> f CreateProcess _delegate_ctlc :: forall f. Functor f => (Bool -> f Bool) -> CreateProcess -> f CreateProcess _detach_console :: forall f. Functor f => (Bool -> f Bool) -> CreateProcess -> f CreateProcess _create_new_console :: forall f. Functor f => (Bool -> f Bool) -> CreateProcess -> f CreateProcess _new_session :: forall f. Functor f => (Bool -> f Bool) -> CreateProcess -> f CreateProcess -- | This module contains helper functions and types built on top of -- System.Process. -- -- They provide concurrent, streaming access to the inputs and outputs of -- external processes. -- -- Consumers from pipes, Parsers from -- pipes-parse and Folds from foldl can be -- used to consume the standard streams, by means of the auxiliary -- Fold1 datatype from pipes-transduce. -- -- The entirety of System.Process and Pipes.Transduce is -- re-exported for convenience. module System.Process.Streaming -- | Execute an external program described by the CreateProcess -- record. -- -- The Streams Applicative specifies how to handle the standard -- streams and the exit code. Since Streams is an Applicative, a -- simple invocation of execute could be -- --
-- >>> execute (piped (shell "echo foo")) (pure ()) ---- -- which would discard the program's stdout and stderr, and ignore the -- exit code. To actually get the exit code: -- --
-- >>> execute (piped (shell "echo foo")) exitCode -- ExitSuccess ---- -- To collect stdout as a lazy ByteString along with the exit -- code: -- --
-- >>> execute (piped (shell "echo foo")) (liftA2 (,) (foldOut intoLazyBytes) exitCode)
-- ("foo\n",ExitSuccess)
--
--
-- execute respects all the fields of the CreateProcess
-- record. If stdout is not piped, but a handler is defined for it, the
-- handler will see an empty stream:
--
--
-- >>> execute ((shell "echo foo"){ std_out = Inherit }) (foldOut intoLazyBytes)
-- foo
-- ""
--
--
-- No effort is made to catch exceptions thrown during execution:
--
-- -- >>> execute (piped (shell "echo foo")) (foldOut (withCont (\_ -> throwIO (userError "oops")))) -- *** Exception: user error (oops) ---- -- However, care is taken to automatically terminate the external process -- if an exception (including asynchronous ones) or other type of error -- happens. This means we can terminate the external process by killing -- the thread that is running execute: -- --
-- >>> forkIO (execute (piped (shell "sleep infinity")) (pure ())) >>= killThread --execute :: CreateProcess -> Streams Void a -> IO a -- | Like execute, but allows the handlers in the Streams -- Applicative to interrupt the execution of the external process by -- returning a Left value, in addition to throwing exceptions. -- This is sometimes more convenient: -- --
-- >>> executeFallibly (piped (shell "sleep infinity")) (foldOut (withFallibleCont (\_ -> pure (Left "oops")))) -- Left "oops" ---- --
-- >>> executeFallibly (piped (shell "exit 1")) validateExitCode -- Left 1 ---- -- The first type parameter of Streams is the error type. If it is -- never used, it remains polymorphic and may unify with Void (as -- required by execute). executeFallibly :: CreateProcess -> Streams e a -> IO (Either e a) -- | Like execute, but std_in will be unbuffered if piped. executeInteractive :: CreateProcess -> Streams Void a -> IO a -- | Like executeFallibly, but std_in will be unbuffered if -- piped. executeInteractiveFallibly :: CreateProcess -> Streams e a -> IO (Either e a) -- | Sets std_in, std_out and std_err in the -- CreateProcess record to CreatePipe. -- -- Any unpiped stream will appear to the Streams handlers as -- empty. piped :: CreateProcess -> CreateProcess -- | The type of handlers that write to piped stdin, consume piped -- stdout and stderr, and work with the process exit -- code, eventually returning a value of type r, except when an -- error e interrups the execution. -- -- Example of a complex handler: -- --
-- >>> :{
-- execute (piped (shell "{ cat ; sleep 1 ; echo eee 1>&2 ; }")) $
-- (\_ _ o e oe ec -> (o,e,oe,ec))
-- <$>
-- feedBytes (Just "aaa")
-- <*>
-- feedBytes (Just "bbb")
-- <*>
-- foldOut intoLazyBytes
-- <*>
-- foldErr intoLazyBytes
-- <*>
-- foldOutErr (combined (PT.lines PT.utf8x) (PT.lines PT.utf8x) PT.intoLazyText)
-- <*>
-- exitCode
-- :}
-- ("aaabbb","eee\n","aaabbb\neee\n",ExitSuccess)
--
data Streams e r
-- | Feed any Foldable container of strict ByteStrings to
-- stdin.
feedBytes :: Foldable f => f ByteString -> Streams e ()
-- | Feed a lazy ByteString to stdin.
feedLazyBytes :: ByteString -> Streams e ()
-- | Feed any Foldable container of strict Textss to
-- stdin, encoding the texts as UTF8.
feedUtf8 :: Foldable f => f Text -> Streams e ()
-- | Feed a lazy Text to stdin, encoding it as UTF8.
feedLazyUtf8 :: Text -> Streams e ()
feedProducer :: Producer ByteString IO () -> Streams e ()
feedProducerM :: MonadIO m => (m () -> IO (Either e a)) -> Producer ByteString m r -> Streams e a
feedSafeProducer :: Producer ByteString (SafeT IO) () -> Streams e ()
feedFallibleProducer :: Producer ByteString (ExceptT e IO) () -> Streams e ()
-- | Feed stdin by running a pipes Consumer. This allows
-- bracketing functions like withFile inside the handler.
feedCont :: (Consumer ByteString IO () -> IO (Either e a)) -> Streams e a
-- | Consume standard output.
foldOut :: Fold1 ByteString e r -> Streams e r
-- | Consume standard error.
foldErr :: Fold1 ByteString e r -> Streams e r
-- | Collect strict ByteStrings into a lazy ByteString.
--
--
-- >>> PT.fold1 intoLazyBytes (mapM_ yield ["aa","bb","cc"])
-- ("aabbcc",())
--
intoLazyBytes :: () => Fold1 ByteString e ByteString
-- | Consume standard output and error together. See also the
-- combine function re-exported from Pipes.Transduce.
foldOutErr :: Fold2 ByteString ByteString e r -> Streams e r
-- | Simply returns the ExitCode.
exitCode :: Streams e ExitCode
-- | Fails with the error code when ExitCode is not
-- ExitSuccess.
validateExitCode :: Streams Int ()
withExitCode :: (ExitCode -> IO (Either e a)) -> Streams e a
instance GHC.Base.Functor (System.Process.Streaming.Streams e)
instance GHC.Base.Functor (System.Process.Streaming.Feed1 b e)
instance GHC.Base.Functor (System.Process.Streaming.Feed1_ b e)
instance Data.Bifunctor.Bifunctor System.Process.Streaming.Streams
instance GHC.Base.Applicative (System.Process.Streaming.Streams e)
instance GHC.Base.Monoid a => GHC.Base.Monoid (System.Process.Streaming.Streams e a)
instance Data.Bifunctor.Bifunctor (System.Process.Streaming.Feed1 b)
instance GHC.Base.Applicative (System.Process.Streaming.Feed1 b e)
instance GHC.Base.Monoid a => GHC.Base.Monoid (System.Process.Streaming.Feed1 b e a)
instance Data.Bifunctor.Bifunctor (System.Process.Streaming.Feed1_ b)
instance GHC.Base.Applicative (System.Process.Streaming.Feed1_ b e)
-- | 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 System.Process.Streaming.Text