| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Conduit.Process
Description
A full tutorial for this module is available at: https://github.com/snoyberg/conduit/blob/master/PROCESS.md.
Some utilities in this module require the threaded runtime because they use
waitForProcess internally.
Note that this is a very thin layer around the Data.Streaming.Process module. In particular, it:
- Provides orphan instances for conduit
- Provides some useful helper functions
Synopsis
- sourceCmdWithConsumer :: MonadIO m => String -> ConduitT ByteString Void m a -> m (ExitCode, a)
- sourceProcessWithConsumer :: MonadIO m => CreateProcess -> ConduitT ByteString Void m a -> m (ExitCode, a)
- sourceCmdWithStreams :: MonadUnliftIO m => String -> ConduitT () ByteString m () -> ConduitT ByteString Void m a -> ConduitT ByteString Void m b -> m (ExitCode, a, b)
- sourceProcessWithStreams :: MonadUnliftIO m => CreateProcess -> ConduitT () ByteString m () -> ConduitT ByteString Void m a -> ConduitT ByteString Void m b -> m (ExitCode, a, b)
- withCheckedProcessCleanup :: (InputSource stdin, OutputSink stderr, OutputSink stdout, MonadUnliftIO m) => CreateProcess -> (stdin -> stdout -> stderr -> m b) -> m b
- newtype FlushInput o (m :: Type -> Type) r = FlushInput (ConduitM (Flush ByteString) o m r)
- newtype BuilderInput o (m :: Type -> Type) r = BuilderInput (ConduitM Builder o m r)
- callCommand :: String -> IO ()
- callProcess :: FilePath -> [String] -> IO ()
- cleanupProcess :: (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) -> IO ()
- createProcess :: CreateProcess -> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
- getCurrentPid :: IO Pid
- getPid :: ProcessHandle -> IO (Maybe Pid)
- getProcessExitCode :: ProcessHandle -> IO (Maybe ExitCode)
- proc :: FilePath -> [String] -> CreateProcess
- rawSystem :: String -> [String] -> IO ExitCode
- readCreateProcess :: CreateProcess -> String -> IO String
- readCreateProcessWithExitCode :: CreateProcess -> String -> IO (ExitCode, String, String)
- readProcess :: FilePath -> [String] -> String -> IO String
- readProcessWithExitCode :: FilePath -> [String] -> String -> IO (ExitCode, String, String)
- runCommand :: String -> IO ProcessHandle
- runInteractiveCommand :: String -> IO (Handle, Handle, Handle, ProcessHandle)
- runInteractiveProcess :: FilePath -> [String] -> Maybe FilePath -> Maybe [(String, String)] -> IO (Handle, Handle, Handle, ProcessHandle)
- runProcess :: FilePath -> [String] -> Maybe FilePath -> Maybe [(String, String)] -> Maybe Handle -> Maybe Handle -> Maybe Handle -> IO ProcessHandle
- shell :: String -> CreateProcess
- showCommandForUser :: FilePath -> [String] -> String
- spawnCommand :: String -> IO ProcessHandle
- spawnProcess :: FilePath -> [String] -> IO ProcessHandle
- system :: String -> IO ExitCode
- terminateProcess :: ProcessHandle -> IO ()
- waitForProcess :: ProcessHandle -> IO ExitCode
- withCreateProcess :: CreateProcess -> (Maybe Handle -> Maybe Handle -> Maybe Handle -> ProcessHandle -> IO a) -> IO a
- createPipe :: IO (Handle, Handle)
- createPipeFd :: IO (FD, FD)
- createProcess_ :: String -> CreateProcess -> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
- interruptProcessGroupOf :: ProcessHandle -> IO ()
- closeStreamingProcessHandle :: MonadIO m => StreamingProcessHandle -> m ()
- getStreamingProcessExitCode :: MonadIO m => StreamingProcessHandle -> m (Maybe ExitCode)
- getStreamingProcessExitCodeSTM :: StreamingProcessHandle -> STM (Maybe ExitCode)
- streamingProcess :: (MonadIO m, InputSource stdin, OutputSink stdout, OutputSink stderr) => CreateProcess -> m (stdin, stdout, stderr, StreamingProcessHandle)
- streamingProcessHandleRaw :: StreamingProcessHandle -> ProcessHandle
- streamingProcessHandleTMVar :: StreamingProcessHandle -> TMVar ExitCode
- waitForStreamingProcess :: MonadIO m => StreamingProcessHandle -> m ExitCode
- waitForStreamingProcessSTM :: StreamingProcessHandle -> STM ExitCode
- withCheckedProcess :: (InputSource stdin, OutputSink stderr, OutputSink stdout, MonadIO m) => CreateProcess -> (stdin -> stdout -> stderr -> m b) -> m b
- type Pid = CPid
- data CmdSpec
- = ShellCommand String
- | RawCommand FilePath [String]
- data CreateProcess = CreateProcess {
- cmdspec :: CmdSpec
- cwd :: Maybe FilePath
- env :: Maybe [(String, String)]
- std_in :: StdStream
- std_out :: StdStream
- std_err :: StdStream
- close_fds :: Bool
- create_group :: Bool
- delegate_ctlc :: Bool
- detach_console :: Bool
- create_new_console :: Bool
- new_session :: Bool
- child_group :: Maybe GroupID
- child_user :: Maybe UserID
- use_process_jobs :: Bool
- data ProcessHandle
- data StdStream
- = Inherit
- | UseHandle Handle
- | CreatePipe
- | NoStream
- data ClosedStream = ClosedStream
- data Inherited = Inherited
- data ProcessExitedUnsuccessfully = ProcessExitedUnsuccessfully CreateProcess ExitCode
- data UseProvidedHandle = UseProvidedHandle
- class InputSource a
- class OutputSink a
- data StreamingProcessHandle
Functions
sourceCmdWithConsumer Source #
Arguments
| :: MonadIO m | |
| => String | command |
| -> ConduitT ByteString Void m a | stdout |
| -> m (ExitCode, a) |
Like sourceProcessWithConsumer but providing the command to be run as
a String.
Requires the threaded runtime.
Since 1.1.2
sourceProcessWithConsumer Source #
Arguments
| :: MonadIO m | |
| => CreateProcess | |
| -> ConduitT ByteString Void m a | stdout |
| -> m (ExitCode, a) |
Given a CreateProcess, run the process, with its output being used as a
Source to feed the provided Consumer. Once the process has completed,
return a tuple of the ExitCode from the process and the output collected
from the Consumer.
Note that, if an exception is raised by the consumer, the process is not
terminated. This behavior is different from sourceProcessWithStreams due
to historical reasons.
Requires the threaded runtime.
Since 1.1.2
Arguments
| :: MonadUnliftIO m | |
| => String | command |
| -> ConduitT () ByteString m () | stdin |
| -> ConduitT ByteString Void m a | stdout |
| -> ConduitT ByteString Void m b | stderr |
| -> m (ExitCode, a, b) |
Like sourceProcessWithStreams but providing the command to be run as
a String.
Requires the threaded runtime.
Since: 1.1.12
sourceProcessWithStreams Source #
Arguments
| :: MonadUnliftIO m | |
| => CreateProcess | |
| -> ConduitT () ByteString m () | stdin |
| -> ConduitT ByteString Void m a | stdout |
| -> ConduitT ByteString Void m b | stderr |
| -> m (ExitCode, a, b) |
Given a CreateProcess, run the process
and feed the provided Producer
to the stdin Sink of the process.
Use the process outputs (stdout, stderr) as Sources
and feed it to the provided Consumers.
Once the process has completed,
return a tuple of the ExitCode from the process
and the results collected from the Consumers.
If an exception is raised by any of the streams, the process is terminated.
IO is required because the streams are run concurrently using the async package
Requires the threaded runtime.
Since: 1.1.12
withCheckedProcessCleanup :: (InputSource stdin, OutputSink stderr, OutputSink stdout, MonadUnliftIO m) => CreateProcess -> (stdin -> stdout -> stderr -> m b) -> m b Source #
Same as withCheckedProcess, but kills the child process in the case of
an exception being thrown by the provided callback function.
Requires the threaded runtime.
Since: 1.1.11
InputSource types
newtype FlushInput o (m :: Type -> Type) r Source #
Wrapper for input source which accepts Flushes. Note that the pipe
will not automatically close then processing completes.
Since: 1.3.2
Constructors
| FlushInput (ConduitM (Flush ByteString) o m r) |
Instances
| (MonadIO m, MonadIO n, r ~ (), r' ~ ()) => InputSource (FlushInput o m r, n r') Source # | |
Defined in Data.Conduit.Process Methods isStdStream :: (Maybe Handle -> IO (FlushInput o m r, n r'), Maybe StdStream) | |
| (MonadIO m, r ~ ()) => InputSource (FlushInput o m r) Source # | |
Defined in Data.Conduit.Process Methods isStdStream :: (Maybe Handle -> IO (FlushInput o m r), Maybe StdStream) | |
newtype BuilderInput o (m :: Type -> Type) r Source #
Wrapper for input source which accepts Builders.
You can pass flush to flush the input. Note
that the pipe will not automatically close when the processing completes.
Since: 1.3.2
Constructors
| BuilderInput (ConduitM Builder o m r) |
Instances
| (MonadIO m, MonadIO n, r ~ (), r' ~ ()) => InputSource (BuilderInput o m r, n r') Source # | |
Defined in Data.Conduit.Process Methods isStdStream :: (Maybe Handle -> IO (BuilderInput o m r, n r'), Maybe StdStream) | |
| (MonadIO m, r ~ ()) => InputSource (BuilderInput o m r) Source # | |
Defined in Data.Conduit.Process Methods isStdStream :: (Maybe Handle -> IO (BuilderInput o m r), Maybe StdStream) | |
Reexport
callCommand :: String -> IO () #
callProcess :: FilePath -> [String] -> IO () #
cleanupProcess :: (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) -> IO () #
createProcess :: CreateProcess -> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) #
getCurrentPid :: IO Pid #
getPid :: ProcessHandle -> IO (Maybe Pid) #
getProcessExitCode :: ProcessHandle -> IO (Maybe ExitCode) #
proc :: FilePath -> [String] -> CreateProcess #
readCreateProcess :: CreateProcess -> String -> IO String #
readCreateProcessWithExitCode :: CreateProcess -> String -> IO (ExitCode, String, String) #
readProcess :: FilePath -> [String] -> String -> IO String #
readProcessWithExitCode :: FilePath -> [String] -> String -> IO (ExitCode, String, String) #
runCommand :: String -> IO ProcessHandle #
runInteractiveCommand :: String -> IO (Handle, Handle, Handle, ProcessHandle) #
runInteractiveProcess :: FilePath -> [String] -> Maybe FilePath -> Maybe [(String, String)] -> IO (Handle, Handle, Handle, ProcessHandle) #
runProcess :: FilePath -> [String] -> Maybe FilePath -> Maybe [(String, String)] -> Maybe Handle -> Maybe Handle -> Maybe Handle -> IO ProcessHandle #
shell :: String -> CreateProcess #
showCommandForUser :: FilePath -> [String] -> String #
spawnCommand :: String -> IO ProcessHandle #
spawnProcess :: FilePath -> [String] -> IO ProcessHandle #
terminateProcess :: ProcessHandle -> IO () #
waitForProcess :: ProcessHandle -> IO ExitCode #
withCreateProcess :: CreateProcess -> (Maybe Handle -> Maybe Handle -> Maybe Handle -> ProcessHandle -> IO a) -> IO a #
createPipe :: IO (Handle, Handle) #
createPipeFd :: IO (FD, FD) #
createProcess_ :: String -> CreateProcess -> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) #
interruptProcessGroupOf :: ProcessHandle -> IO () #
closeStreamingProcessHandle :: MonadIO m => StreamingProcessHandle -> m () #
getStreamingProcessExitCode :: MonadIO m => StreamingProcessHandle -> m (Maybe ExitCode) #
getStreamingProcessExitCodeSTM :: StreamingProcessHandle -> STM (Maybe ExitCode) #
streamingProcess :: (MonadIO m, InputSource stdin, OutputSink stdout, OutputSink stderr) => CreateProcess -> m (stdin, stdout, stderr, StreamingProcessHandle) #
streamingProcessHandleTMVar :: StreamingProcessHandle -> TMVar ExitCode #
waitForStreamingProcess :: MonadIO m => StreamingProcessHandle -> m ExitCode #
withCheckedProcess :: (InputSource stdin, OutputSink stderr, OutputSink stdout, MonadIO m) => CreateProcess -> (stdin -> stdout -> stderr -> m b) -> m b #
Constructors
| ShellCommand String | |
| RawCommand FilePath [String] |
Instances
| IsString CmdSpec # | |
Defined in System.Process.Common Methods fromString :: String -> CmdSpec | |
| Show CmdSpec # | |
| Eq CmdSpec # | |
data CreateProcess #
Constructors
| CreateProcess | |
Fields
| |
Instances
| Show CreateProcess # | |
Defined in System.Process.Common Methods showsPrec :: Int -> CreateProcess -> ShowS show :: CreateProcess -> String showList :: [CreateProcess] -> ShowS | |
| Eq CreateProcess # | |
Defined in System.Process.Common | |
data ProcessHandle #
Constructors
| Inherit | |
| UseHandle Handle | |
| CreatePipe | |
| NoStream |
data ClosedStream #
Constructors
| ClosedStream |
Instances
| InputSource ClosedStream # | |
Defined in Data.Streaming.Process Methods isStdStream :: (Maybe Handle -> IO ClosedStream, Maybe StdStream) | |
| OutputSink ClosedStream # | |
Defined in Data.Streaming.Process Methods osStdStream :: (Maybe Handle -> IO ClosedStream, Maybe StdStream) | |
Constructors
| Inherited |
Instances
| InputSource Inherited # | |
Defined in Data.Streaming.Process Methods isStdStream :: (Maybe Handle -> IO Inherited, Maybe StdStream) | |
| OutputSink Inherited # | |
Defined in Data.Streaming.Process Methods osStdStream :: (Maybe Handle -> IO Inherited, Maybe StdStream) | |
data ProcessExitedUnsuccessfully #
Constructors
| ProcessExitedUnsuccessfully CreateProcess ExitCode |
Instances
| Exception ProcessExitedUnsuccessfully # | |
Defined in Data.Streaming.Process Methods toException :: ProcessExitedUnsuccessfully -> SomeException fromException :: SomeException -> Maybe ProcessExitedUnsuccessfully displayException :: ProcessExitedUnsuccessfully -> String backtraceDesired :: ProcessExitedUnsuccessfully -> Bool | |
| Show ProcessExitedUnsuccessfully # | |
Defined in Data.Streaming.Process Methods showsPrec :: Int -> ProcessExitedUnsuccessfully -> ShowS show :: ProcessExitedUnsuccessfully -> String showList :: [ProcessExitedUnsuccessfully] -> ShowS | |
data UseProvidedHandle #
Constructors
| UseProvidedHandle |
Instances
| InputSource UseProvidedHandle # | |
Defined in Data.Streaming.Process Methods isStdStream :: (Maybe Handle -> IO UseProvidedHandle, Maybe StdStream) | |
| OutputSink UseProvidedHandle # | |
Defined in Data.Streaming.Process Methods osStdStream :: (Maybe Handle -> IO UseProvidedHandle, Maybe StdStream) | |
class InputSource a #
Minimal complete definition
isStdStream
Instances
| InputSource Handle # | |
Defined in Data.Streaming.Process.Internal Methods isStdStream :: (Maybe Handle -> IO Handle, Maybe StdStream) | |
| InputSource ClosedStream # | |
Defined in Data.Streaming.Process Methods isStdStream :: (Maybe Handle -> IO ClosedStream, Maybe StdStream) | |
| InputSource Inherited # | |
Defined in Data.Streaming.Process Methods isStdStream :: (Maybe Handle -> IO Inherited, Maybe StdStream) | |
| InputSource UseProvidedHandle # | |
Defined in Data.Streaming.Process Methods isStdStream :: (Maybe Handle -> IO UseProvidedHandle, Maybe StdStream) | |
| (r ~ (), r' ~ (), MonadIO m, MonadIO n, i ~ ByteString) => InputSource (ConduitM i o m r, n r') Source # | |
Defined in Data.Conduit.Process Methods isStdStream :: (Maybe Handle -> IO (ConduitM i o m r, n r'), Maybe StdStream) | |
| (MonadIO m, MonadIO n, r ~ (), r' ~ ()) => InputSource (BuilderInput o m r, n r') Source # | |
Defined in Data.Conduit.Process Methods isStdStream :: (Maybe Handle -> IO (BuilderInput o m r, n r'), Maybe StdStream) | |
| (MonadIO m, MonadIO n, r ~ (), r' ~ ()) => InputSource (FlushInput o m r, n r') Source # | |
Defined in Data.Conduit.Process Methods isStdStream :: (Maybe Handle -> IO (FlushInput o m r, n r'), Maybe StdStream) | |
| (MonadIO m, r ~ ()) => InputSource (BuilderInput o m r) Source # | |
Defined in Data.Conduit.Process Methods isStdStream :: (Maybe Handle -> IO (BuilderInput o m r), Maybe StdStream) | |
| (MonadIO m, r ~ ()) => InputSource (FlushInput o m r) Source # | |
Defined in Data.Conduit.Process Methods isStdStream :: (Maybe Handle -> IO (FlushInput o m r), Maybe StdStream) | |
| (r ~ (), MonadIO m, i ~ ByteString) => InputSource (ConduitM i o m r) Source # | |
Defined in Data.Conduit.Process Methods isStdStream :: (Maybe Handle -> IO (ConduitM i o m r), Maybe StdStream) | |
class OutputSink a #
Minimal complete definition
osStdStream
Instances
| OutputSink Handle # | |
Defined in Data.Streaming.Process.Internal Methods osStdStream :: (Maybe Handle -> IO Handle, Maybe StdStream) | |
| OutputSink ClosedStream # | |
Defined in Data.Streaming.Process Methods osStdStream :: (Maybe Handle -> IO ClosedStream, Maybe StdStream) | |
| OutputSink Inherited # | |
Defined in Data.Streaming.Process Methods osStdStream :: (Maybe Handle -> IO Inherited, Maybe StdStream) | |
| OutputSink UseProvidedHandle # | |
Defined in Data.Streaming.Process Methods osStdStream :: (Maybe Handle -> IO UseProvidedHandle, Maybe StdStream) | |
| (r ~ (), r' ~ (), MonadIO m, MonadIO n, o ~ ByteString) => OutputSink (ConduitM i o m r, n r') Source # | |
Defined in Data.Conduit.Process Methods osStdStream :: (Maybe Handle -> IO (ConduitM i o m r, n r'), Maybe StdStream) | |
| (r ~ (), MonadIO m, o ~ ByteString) => OutputSink (ConduitM i o m r) Source # | |
Defined in Data.Conduit.Process Methods osStdStream :: (Maybe Handle -> IO (ConduitM i o m r), Maybe StdStream) | |
data StreamingProcessHandle #
Orphan instances
| (r ~ (), r' ~ (), MonadIO m, MonadIO n, i ~ ByteString) => InputSource (ConduitM i o m r, n r') Source # | |
Methods isStdStream :: (Maybe Handle -> IO (ConduitM i o m r, n r'), Maybe StdStream) | |
| (r ~ (), r' ~ (), MonadIO m, MonadIO n, o ~ ByteString) => OutputSink (ConduitM i o m r, n r') Source # | |
Methods osStdStream :: (Maybe Handle -> IO (ConduitM i o m r, n r'), Maybe StdStream) | |
| (r ~ (), MonadIO m, i ~ ByteString) => InputSource (ConduitM i o m r) Source # | |
Methods isStdStream :: (Maybe Handle -> IO (ConduitM i o m r), Maybe StdStream) | |
| (r ~ (), MonadIO m, o ~ ByteString) => OutputSink (ConduitM i o m r) Source # | |
Methods osStdStream :: (Maybe Handle -> IO (ConduitM i o m r), Maybe StdStream) | |