Safe Haskell | None |
---|---|
Language | Haskell2010 |
Please see the README.md file for examples of using this API.
- data ProcessConfig stdin stdout stderr
- data StreamSpec streamType a
- data StreamType
- data Process stdin stdout stderr
- proc :: FilePath -> [String] -> ProcessConfig () () ()
- shell :: String -> ProcessConfig () () ()
- setStdin :: StreamSpec STInput stdin -> ProcessConfig stdin0 stdout stderr -> ProcessConfig stdin stdout stderr
- setStdout :: StreamSpec STOutput stdout -> ProcessConfig stdin stdout0 stderr -> ProcessConfig stdin stdout stderr
- setStderr :: StreamSpec STOutput stderr -> ProcessConfig stdin stdout stderr0 -> ProcessConfig stdin stdout stderr
- setWorkingDir :: FilePath -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout stderr
- setEnv :: [(String, String)] -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout stderr
- setCloseFds :: Bool -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout stderr
- setCreateGroup :: Bool -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout stderr
- setDelegateCtlc :: Bool -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout stderr
- setDetachConsole :: Bool -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout stderr
- setCreateNewConsole :: Bool -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout stderr
- setNewSession :: Bool -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout stderr
- setChildGroup :: GroupID -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout stderr
- setChildUser :: UserID -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout stderr
- mkStreamSpec :: StdStream -> (ProcessConfig () () () -> Maybe Handle -> IO (a, IO ())) -> StreamSpec streamType a
- inherit :: StreamSpec anyStreamType ()
- closed :: StreamSpec anyStreamType ()
- byteStringInput :: ByteString -> StreamSpec STInput ()
- byteStringOutput :: StreamSpec STOutput (STM ByteString)
- createPipe :: StreamSpec anyStreamType Handle
- useHandleOpen :: Handle -> StreamSpec anyStreamType ()
- useHandleClose :: Handle -> StreamSpec anyStreamType ()
- createSink :: MonadIO m => StreamSpec STInput (ConduitM ByteString o m ())
- createSource :: MonadIO m => StreamSpec STOutput (ConduitM i ByteString m ())
- startProcess :: MonadIO m => ProcessConfig stdin stdout stderr -> m (Process stdin stdout stderr)
- stopProcess :: MonadIO m => Process stdin stdout stderr -> m ()
- withProcess :: (MonadIO m, MonadMask m) => ProcessConfig stdin stdout stderr -> (Process stdin stdout stderr -> m a) -> m a
- withProcess_ :: (MonadIO m, MonadMask m) => ProcessConfig stdin stdout stderr -> (Process stdin stdout stderr -> m a) -> m a
- readProcess :: MonadIO m => ProcessConfig stdin stdoutIgnored stderrIgnored -> m (ExitCode, ByteString, ByteString)
- readProcess_ :: MonadIO m => ProcessConfig stdin stdoutIgnored stderrIgnored -> m (ByteString, ByteString)
- runProcess :: MonadIO m => ProcessConfig stdin stdout stderr -> m ExitCode
- runProcess_ :: MonadIO m => ProcessConfig stdin stdout stderr -> m ()
- waitExitCode :: MonadIO m => Process stdin stdout stderr -> m ExitCode
- waitExitCodeSTM :: Process stdin stdout stderr -> STM ExitCode
- getExitCode :: MonadIO m => Process stdin stdout stderr -> m (Maybe ExitCode)
- getExitCodeSTM :: Process stdin stdout stderr -> STM (Maybe ExitCode)
- checkExitCode :: MonadIO m => Process stdin stdout stderr -> m ()
- checkExitCodeSTM :: Process stdin stdout stderr -> STM ()
- getStdin :: Process stdin stdout stderr -> stdin
- getStdout :: Process stdin stdout stderr -> stdout
- getStderr :: Process stdin stdout stderr -> stderr
- data ExitCodeException = ExitCodeException {
- eceExitCode :: ExitCode
- eceProcessConfig :: ProcessConfig () () ()
- eceStdout :: ByteString
- eceStderr :: ByteString
- data ByteStringOutputException = ByteStringOutputException SomeException (ProcessConfig () () ())
Types
data ProcessConfig stdin stdout stderr Source #
An abstract configuration for a process, which can then be
launched into an actual running Process
. Takes three type
parameters, providing the types of standard input, standard output,
and standard error, respectively.
There are three ways to construct a value of this type:
- With the
proc
smart constructor, which takes a command name and a list of arguments. - With the
shell
smart constructor, which takes a shell string - With the
IsString
instance via OverloadedStrings. If you provide it a string with no spaces (e.g.,"date"
), it will treat it as a raw command with no arguments (e.g.,proc "date" []
). If it has spaces, it will useshell
.
In all cases, the default for all three streams is to inherit the streams from the parent process. For other settings, see the setters below for default values.
Since: 0.1.0.0
data StreamSpec streamType a Source #
A specification for how to create one of the three standard child streams. See examples below.
Since: 0.1.0.0
Functor (StreamSpec streamType) Source # | |
((~) StreamType streamType STInput, (~) * res ()) => IsString (StreamSpec streamType res) Source # | This instance uses Since: 0.1.0.0 |
data StreamType Source #
Whether a stream is an input stream or output stream. Note that
this is from the perspective of the child process, so that a
child's standard input stream is an STInput
, even though the
parent process will be writing to it.
Since: 0.1.0.0
data Process stdin stdout stderr Source #
A running process. The three type parameters provide the type of the standard input, standard output, and standard error streams.
Since: 0.1.0.0
ProcessConfig
Smart constructors
proc :: FilePath -> [String] -> ProcessConfig () () () Source #
Create a ProcessConfig
from the given command and arguments.
Since: 0.1.0.0
shell :: String -> ProcessConfig () () () Source #
Create a ProcessConfig
from the given shell command.
Since: 0.1.0.0
Setters
setStdin :: StreamSpec STInput stdin -> ProcessConfig stdin0 stdout stderr -> ProcessConfig stdin stdout stderr Source #
setStdout :: StreamSpec STOutput stdout -> ProcessConfig stdin stdout0 stderr -> ProcessConfig stdin stdout stderr Source #
setStderr :: StreamSpec STOutput stderr -> ProcessConfig stdin stdout stderr0 -> ProcessConfig stdin stdout stderr Source #
setWorkingDir :: FilePath -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout stderr Source #
Set the working directory of the child process.
Default: current process's working directory.
Since: 0.1.0.0
setEnv :: [(String, String)] -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout stderr Source #
Set the environment variables of the child process.
Default: current process's environment.
Since: 0.1.0.0
setCloseFds :: Bool -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout stderr Source #
Should we close all file descriptors besides stdin, stdout, and
stderr? See close_fds
for more information.
Default: False
Since: 0.1.0.0
setCreateGroup :: Bool -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout stderr Source #
Should we create a new process group?
Default: False
Since: 0.1.0.0
setDelegateCtlc :: Bool -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout stderr Source #
Delegate handling of Ctrl-C to the child. For more information,
see delegate_ctlc
.
Default: False
Since: 0.1.0.0
setDetachConsole :: Bool -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout stderr Source #
setCreateNewConsole :: Bool -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout stderr Source #
setNewSession :: Bool -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout stderr Source #
Set a new session with the POSIX setsid
syscall, does nothing
on non-POSIX. See new_session
.
Default: False
Since: 0.1.0.0
setChildGroup :: GroupID -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout stderr Source #
Set the child process's group ID with the POSIX setgid
syscall,
does nothing on non-POSIX. See child_group
.
Default: False
Since: 0.1.0.0
setChildUser :: UserID -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout stderr Source #
Set the child process's user ID with the POSIX setuid
syscall,
does nothing on non-POSIX. See child_user
.
Default: False
Since: 0.1.0.0
Stream specs
mkStreamSpec :: StdStream -> (ProcessConfig () () () -> Maybe Handle -> IO (a, IO ())) -> StreamSpec streamType a Source #
Create a new StreamSpec
from the given StdStream
and a
helper function. This function:
- Takes as input the raw
Maybe Handle
returned by thecreateProcess
function. This will be determined by theStdStream
argument. - Returns the actual stream value
a
, as well as a cleanup - function to be run when calling
stopProcess
.
Since: 0.1.0.0
inherit :: StreamSpec anyStreamType () Source #
A stream spec which simply inherits the stream of the parent process.
Since: 0.1.0.0
closed :: StreamSpec anyStreamType () Source #
A stream spec which will close the stream for the child process.
Since: 0.1.0.0
byteStringInput :: ByteString -> StreamSpec STInput () Source #
An input stream spec which sets the input to the given
ByteString
. A separate thread will be forked to write the
contents to the child process.
Since: 0.1.0.0
byteStringOutput :: StreamSpec STOutput (STM ByteString) Source #
Capture the output of a process in a ByteString
.
This function will fork a separate thread to consume all input from
the process, and will only make the results available when the
underlying Handle
is closed. As this is provided as an STM
action, you can either check if the result is available, or block
until it's ready.
In the event of any exception occurring when reading from the
Handle
, the STM
action will throw a
ByteStringOutputException
.
Since: 0.1.0.0
createPipe :: StreamSpec anyStreamType Handle Source #
Create a new pipe between this process and the child, and return
a Handle
to communicate with the child.
Since: 0.1.0.0
useHandleOpen :: Handle -> StreamSpec anyStreamType () Source #
Use the provided Handle
for the child process, and when the
process exits, do not close it. This is useful if, for example,
you want to have multiple processes write to the same log file
sequentially.
Since: 0.1.0.0
useHandleClose :: Handle -> StreamSpec anyStreamType () Source #
Use the provided Handle
for the child process, and when the
process exits, close it. If you have no reason to keep the Handle
open, you should use this over useHandleOpen
.
Since: 0.1.0.0
Conduit
createSink :: MonadIO m => StreamSpec STInput (ConduitM ByteString o m ()) Source #
Provide input to a process by writing to a conduit.
Since: 0.1.0.0
createSource :: MonadIO m => StreamSpec STOutput (ConduitM i ByteString m ()) Source #
Read output from a process by read from a conduit.
Since: 0.1.0.0
Launch a process
startProcess :: MonadIO m => ProcessConfig stdin stdout stderr -> m (Process stdin stdout stderr) Source #
Launch a process based on the given ProcessConfig
. You should
ensure that you close stopProcess
on the result. It's usually
better to use one of the functions in this module which ensures
stopProcess
is called, such as withProcess
.
Since: 0.1.0.0
stopProcess :: MonadIO m => Process stdin stdout stderr -> m () Source #
Close a process and release any resources acquired. This will
ensure terminateProcess
is called, wait for the process to
actually exit, and then close out resources allocated for the
streams. In the event of any cleanup exceptions being thrown this
will throw an exception.
Since: 0.1.0.0
withProcess :: (MonadIO m, MonadMask m) => ProcessConfig stdin stdout stderr -> (Process stdin stdout stderr -> m a) -> m a Source #
Use the bracket pattern to call startProcess
and ensure
stopProcess
is called.
Since: 0.1.0.0
withProcess_ :: (MonadIO m, MonadMask m) => ProcessConfig stdin stdout stderr -> (Process stdin stdout stderr -> m a) -> m a Source #
Same as withProcess
, but also calls checkExitCode
Since: 0.1.0.0
readProcess :: MonadIO m => ProcessConfig stdin stdoutIgnored stderrIgnored -> m (ExitCode, ByteString, ByteString) Source #
Run a process, capture its standard output and error as a
ByteString
, wait for it to complete, and then return its exit
code, output, and error.
Note that any previously used setStdout
or setStderr
will be
overridden.
Since: 0.1.0.0
readProcess_ :: MonadIO m => ProcessConfig stdin stdoutIgnored stderrIgnored -> m (ByteString, ByteString) Source #
Same as readProcess
, but instead of returning the ExitCode
,
checks it with checkExitCode
.
Since: 0.1.0.0
runProcess :: MonadIO m => ProcessConfig stdin stdout stderr -> m ExitCode Source #
Run the given process, wait for it to exit, and returns its
ExitCode
.
Since: 0.1.0.0
runProcess_ :: MonadIO m => ProcessConfig stdin stdout stderr -> m () Source #
Same as runProcess
, but ignores the ExitCode
.
Since: 0.1.0.0
Interact with a process
Process exit code
waitExitCode :: MonadIO m => Process stdin stdout stderr -> m ExitCode Source #
Wait for the process to exit and then return its ExitCode
.
Since: 0.1.0.0
waitExitCodeSTM :: Process stdin stdout stderr -> STM ExitCode Source #
Same as waitExitCode
, but in STM
.
Since: 0.1.0.0
getExitCode :: MonadIO m => Process stdin stdout stderr -> m (Maybe ExitCode) Source #
Check if a process has exited and, if so, return its ExitCode
.
Since: 0.1.0.0
getExitCodeSTM :: Process stdin stdout stderr -> STM (Maybe ExitCode) Source #
Same as getExitCode
, but in STM
.
Since: 0.1.0.0
checkExitCode :: MonadIO m => Process stdin stdout stderr -> m () Source #
Wait for a process to exit, and ensure that it exited
successfully. If not, throws an ExitCodeException
.
Since: 0.1.0.0
checkExitCodeSTM :: Process stdin stdout stderr -> STM () Source #
Same as checkExitCode
, but in STM
.
Since: 0.1.0.0
Process streams
getStdin :: Process stdin stdout stderr -> stdin Source #
Get the child's standard input stream value.
Since: 0.1.0.0
getStdout :: Process stdin stdout stderr -> stdout Source #
Get the child's standard output stream value.
Since: 0.1.0.0
getStderr :: Process stdin stdout stderr -> stderr Source #
Get the child's standard error stream value.
Since: 0.1.0.0
Exceptions
data ExitCodeException Source #
Exception thrown by checkExitCode
in the event of a non-success
exit code. Note that checkExitCode
is called by other functions
as well, like runProcess_
or readProcess_
.
Since: 0.1.0.0
ExitCodeException | |
|
data ByteStringOutputException Source #
Wrapper for when an exception is thrown when reading from a child
process, used by byteStringOutput
.
Since: 0.1.0.0
ByteStringOutputException SomeException (ProcessConfig () () ()) |