Moduletyped-process-effectful-1.0.0.1Haskell2010
Effectful.Process.Typed
This module provides effectful bindings for typed-process.
- 10 types
- 61 values
- Packagetyped-process-effectful-1.0.0.1
- Exports71
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceTyped.hs
Process effect
2 declarationsThis is merely an alias for runProcess since that name clashes with runProcess, i.e.:
runTypedProcess = Effectful.Process.runProcessLaunch a process
16 declarationsLifted startProcess.
Lifted stopProcess.
Lifted withProcessWait.
Lifted withProcessWait_.
Lifted withProcessTerm.
Lifted withProcessTerm_.
Lifted readProcess.
Lifted readProcess_.
Lifted runProcess.
Lifted runProcess_.
Lifted readProcessStdout.
Lifted readProcessStdout_.
Lifted readProcessStderr.
Lifted readProcessStderr_.
Lifted readProcessInterleaved.
Lifted readProcessInterleaved_.
Process exit code
3 declarationsLifted waitExitCode.
Lifted getExitCode.
Lifted checkExitCode.
Re-exports from System.Process.Typed
50 declarationsCreate a ProcessConfig from the given command and arguments.
A running process. The three type parameters provide the type of the standard input, standard output, and standard error streams.
To interact with a Process use the functions from the section
Interact with a process.
Defines the exit codes that a program can return.
Constructors
ExitSuccessindicates successful termination;
ExitFailure Intindicates program failure with an exit code. The exact interpretation of the code is operating-system dependent. In particular, some values may be prohibited (e.g. 0 on a POSIX-compliant system).
Instances8Eq, Ord, Read, Show, Generic, Exception, …
Eq ExitCodeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.ExceptionOrd ExitCodeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.ExceptionRead ExitCodeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.ExceptionShow ExitCodeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.ExceptionGeneric ExitCodeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.ExceptionException ExitCodeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.ExceptionNFData ExitCodeDefined in deepseq-1.5.0.0 · Control.DeepSeqtype Rep ExitCode = D1 ('MetaDataDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Exception"ExitCode"
"GHC.Internal.IO.Exception"
"ghc-internal"
'False) (C1 ('MetaCons"ExitSuccess"
'PrefixI 'False) U1 :+: C1 ('MetaCons"ExitFailure"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))
Wrapper for when an exception is thrown when reading from a child process, used by byteStringOutput.
Constructors
ByteStringOutputException SomeException (ProcessConfig () () ())
Instances2Show, Exception
Show ByteStringOutputExceptionDefined in typed-process-0.2.13.0 · System.Process.Typed.InternalException ByteStringOutputExceptionDefined in typed-process-0.2.13.0 · System.Process.Typed.Internal
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_.
Note that several functions that throw an ExitCodeException intentionally do not populate eceStdout or eceStderr. This prevents unbounded memory usage for large stdout and stderrs.
Functions which do include eceStdout or eceStderr (like readProcess_) state so in their documentation.
Constructors
Instances2Show, Exception
Show ExitCodeExceptionDefined in typed-process-0.2.13.0 · System.Process.Typed.InternalException ExitCodeExceptionDefined in typed-process-0.2.13.0 · System.Process.Typed.Internal
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.
Once you have a ProcessConfig you can launch a process from it
using the functions in the section Launch a
process.
Instances2Show, IsString
Show (ProcessConfig stdin stdout stderr)Defined in typed-process-0.2.13.0 · System.Process.Typed.Internal(stdin ~ (), stdout ~ (), stderr ~ ()) => IsString (ProcessConfig stdin stdout stderr)Defined in typed-process-0.2.13.0 · System.Process.Typed.Internal
A specification for how to create one of the three standard child
streams, stdin, stdout and stderr. A StreamSpec can be
thought of as containing
A type safe version of StdStream from System.Process. This determines whether the stream should be inherited from the parent process, piped to or from a Handle, etc.
A means of accessing the stream as a value of type
aA cleanup action which will be run on the stream once the process terminates
To create a StreamSpec see the section Stream
specs.
Instances2Functor, IsString
Functor (StreamSpec streamType)Defined in typed-process-0.2.13.0 · System.Process.Typed.Internal(streamType ~ 'STInput, res ~ ()) => IsString (StreamSpec streamType res)Defined in typed-process-0.2.13.0 · System.Process.Typed.InternalThis instance uses byteStringInput to convert a raw string into a stream of input for a child process.
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.
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.
A stream spec which will close the stream for the child process. You usually do not want to use this, as it will leave the corresponding file descriptor unassigned and hence available for re-use in the child process. Prefer nullStream unless you're certain you want this behavior.
Create a new pipe between this process and the child, and return a Handle to communicate with the child.
A stream spec which simply inherits the stream of the parent process.
mkPipeStreamSpec :: (ProcessConfig () () () -> Handle -> IO (a, IO ()))-> StreamSpec streamType a
Create a new CreatePipe StreamSpec from the given function. This function:
Takes as input the
Handlereturned by the createProcess function. See createProcess for more details.Returns the actual stream value
a, as well as a cleanup function to be run when callingstopProcess.
mkStreamSpec :: StdStream-> (ProcessConfig () () () -> Maybe Handle -> IO (a, IO ()))-> StreamSpec streamType a
Create a new StreamSpec from the given StdStream and a helper function. This function:
Takes as input the raw
Maybe Handlereturned by the createProcess function. The handle will beJustHandle if the StdStream argument is CreatePipe andNothingotherwise. See createProcess for more details.Returns the actual stream value
a, as well as a cleanup function to be run when callingstopProcess.
If making a StreamSpec with CreatePipe, prefer mkPipeStreamSpec, which encodes the invariant that a Handle is created.
A stream spec which is empty when used for for input and discards output. Note this requires your platform's null device to be available when the process is started.
setChildGroup :: GroupID-> ProcessConfig stdin stdout stderr-> ProcessConfig stdin stdout stderr
Set the child process's group ID with the POSIX setgid syscall,
does nothing on non-POSIX. See child_group.
Default: False
Inherit the group from the parent process.
Set the child process's user ID with the POSIX setuid syscall,
does nothing on non-POSIX. See child_user.
Default: False
Inherit the user from the parent process.
Should we close all file descriptors besides stdin, stdout, and stderr? See close_fds for more information.
Default: False
Should we create a new process group?
Default: False
setCreateNewConsole :: Bool-> ProcessConfig stdin stdout stderr-> ProcessConfig stdin stdout stderr
Create new console on Windows, see create_new_console.
Default: False
setDelegateCtlc :: Bool-> ProcessConfig stdin stdout stderr-> ProcessConfig stdin stdout stderr
Delegate handling of Ctrl-C to the child. For more information, see delegate_ctlc.
Default: False
setDetachConsole :: Bool-> ProcessConfig stdin stdout stderr-> ProcessConfig stdin stdout stderr
Detach console on Windows, see detach_console.
Default: False
setEnv :: [(String, String)]-> ProcessConfig stdin stdout stderr-> ProcessConfig stdin stdout stderr
Set the environment variables of the child process.
Default: current process's environment.
Inherit the environment variables from the parent process.
Set a new session with the POSIX setsid syscall, does nothing
on non-POSIX. See new_session.
Default: False
setStderr :: StreamSpec 'STOutput stderr-> ProcessConfig stdin stdout stderr0-> ProcessConfig stdin stdout stderr
Set the child's standard error stream to the given StreamSpec.
Default: inherit
setStdin :: StreamSpec 'STInput stdin-> ProcessConfig stdin0 stdout stderr-> ProcessConfig stdin stdout stderr
Set the child's standard input stream to the given StreamSpec.
Default: inherit
setStdout :: StreamSpec 'STOutput stdout-> ProcessConfig stdin stdout0 stderr-> ProcessConfig stdin stdout stderr
Set the child's standard output stream to the given StreamSpec.
Default: inherit
setWorkingDir :: FilePath-> ProcessConfig stdin stdout stderr-> ProcessConfig stdin stdout stderr
Set the working directory of the child process.
Default: current process's working directory.
Inherit the working directory from the parent process.
Create a ProcessConfig from the given shell command.
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.
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.
Deprecated. Please consider using withProcessWait_, or instead use withProcessTerm_
Deprecated synonym for withProcessTerm_.
Deprecated. Please consider using withProcessWait, or instead use withProcessTerm
Deprecated synonym for withProcessTerm.
Same as checkExitCode, but in STM.
Get an ExitCodeException containing no data other than the exit code and process config.
Unlike checkExitCode and similar, this will return an ExitCodeException even if the process exits with ExitSuccess.
Get an ExitCodeException containing the process's stdout and stderr data.
Note that this will call waitExitCode to block until the process exits, if it has not exited already.
Unlike checkExitCode and similar, this will return an ExitCodeException even if the process exits with ExitSuccess.
Same as getExitCode, but in STM.
Returns the PID (process ID) of a subprocess.
Nothing is returned if the underlying ProcessHandle was already closed. Otherwise a PID is returned that remains valid as long as the handle is open. The operating system may reuse the PID as soon as the last handle to the process is closed.
Get the child's standard error stream value.
Get the child's standard input stream value.
Get the child's standard output stream value.
Take ProcessHandle out of the Process.
This method is needed in cases one need to use low level functions
from the process package. Use cases for this method are:
Send a special signal to the process.
Terminate the process group instead of terminating single process.
Use platform specific API on the underlying process.
This method is considered unsafe because the actions it performs on
the underlying process may overlap with the functionality that
typed-process provides. For example the user should not call
waitForProcess on the process handle as either
waitForProcess or stopProcess will lock.
Additionally, even if process was terminated by the
terminateProcess or by sending signal,
stopProcess should be called either way in order to cleanup resources
allocated by the typed-process.
Same as waitExitCode, but in STM.
The platform specific type for a process identifier.
This is always an integral type. Width and signedness are platform specific.
Constructors
InheritInherit Handle from parent
UseHandle HandleUse the supplied Handle
CreatePipeCreate a new pipe. The returned
Handlewill use the default encoding and newline translation mode (just likeHandles created byopenFile).NoStreamClose the stream's file descriptor without passing a Handle. On POSIX systems this may lead to strange behavior in the child process because attempting to read or write after the file has been closed throws an error. This should only be used with child processes that don't use the file descriptor at all. If you wish to ignore the child process's output you should either create a pipe and drain it manually or pass a
Handlethat writes to/dev/null.