| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Effects.System.Process
Description
Provides the MonadProcess typeclass for process effects.
Since: 0.1
Synopsis
- class Monad m => MonadProcess (m :: Type -> Type) where
- createProcess :: CreateProcess -> m (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
- createProcess_ :: String -> CreateProcess -> m (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
- callProcess :: FilePath -> [String] -> m ()
- callCommand :: String -> m ()
- spawnProcess :: FilePath -> [String] -> m ProcessHandle
- spawnCommand :: String -> m ProcessHandle
- readCreateProcess :: CreateProcess -> String -> m String
- readProcess :: FilePath -> [String] -> String -> m String
- readCreateProcessWithExitCode :: CreateProcess -> String -> m (ExitCode, String, String)
- readProcessWithExitCode :: FilePath -> [String] -> String -> m (ExitCode, String, String)
- withCreateProcess :: HasCallStack => CreateProcess -> (Maybe Handle -> Maybe Handle -> Maybe Handle -> ProcessHandle -> m a) -> m a
- cleanupProcess :: (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) -> m ()
- getPid :: ProcessHandle -> m (Maybe Pid)
- getCurrentPid :: m Pid
- waitForProcess :: ProcessHandle -> m ExitCode
- getProcessExitCode :: ProcessHandle -> m (Maybe ExitCode)
- terminateProcess :: ProcessHandle -> m ()
- interruptProcessGroupOf :: ProcessHandle -> m ()
- createPipe :: m (Handle, Handle)
- createPipeFd :: m (FD, FD)
- createProcess :: MonadProcess m => CreateProcess -> m (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
- createProcess_ :: MonadProcess m => String -> CreateProcess -> m (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
- shell :: String -> CreateProcess
- proc :: FilePath -> [String] -> CreateProcess
- 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 CmdSpec
- data StdStream
- data ProcessHandle
- callProcess :: MonadProcess m => FilePath -> [String] -> m ()
- callCommand :: MonadProcess m => String -> m ()
- spawnProcess :: MonadProcess m => FilePath -> [String] -> m ProcessHandle
- spawnCommand :: MonadProcess m => String -> m ProcessHandle
- readCreateProcess :: MonadProcess m => CreateProcess -> String -> m String
- readProcess :: MonadProcess m => FilePath -> [String] -> String -> m String
- readCreateProcessWithExitCode :: MonadProcess m => CreateProcess -> String -> m (ExitCode, String, String)
- readProcessWithExitCode :: MonadProcess m => FilePath -> [String] -> String -> m (ExitCode, String, String)
- withCreateProcess :: (MonadProcess m, HasCallStack) => CreateProcess -> (Maybe Handle -> Maybe Handle -> Maybe Handle -> ProcessHandle -> m a) -> m a
- cleanupProcess :: MonadProcess m => (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) -> m ()
- showCommandForUser :: FilePath -> [String] -> String
- type Pid = CPid
- getPid :: MonadProcess m => ProcessHandle -> m (Maybe Pid)
- getCurrentPid :: MonadProcess m => m Pid
- waitForProcess :: MonadProcess m => ProcessHandle -> m ExitCode
- getProcessExitCode :: MonadProcess m => ProcessHandle -> m (Maybe ExitCode)
- terminateProcess :: MonadProcess m => ProcessHandle -> m ()
- interruptProcessGroupOf :: MonadProcess m => ProcessHandle -> m ()
- createPipe :: MonadProcess m => m (Handle, Handle)
- createPipeFd :: MonadProcess m => m (FD, FD)
- data Handle
Effect
class Monad m => MonadProcess (m :: Type -> Type) where Source #
Effect for launching processes. API largely follows process.
Since: 0.1
Methods
Arguments
| :: CreateProcess | . |
| -> m (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) |
Since: 0.1
Arguments
| :: String | . |
| -> CreateProcess | |
| -> m (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) |
Since: 0.1
callProcess :: FilePath -> [String] -> m () Source #
Since: 0.1
callCommand :: String -> m () Source #
Since: 0.1
spawnProcess :: FilePath -> [String] -> m ProcessHandle Source #
Since: 0.1
spawnCommand :: String -> m ProcessHandle Source #
Since: 0.1
readCreateProcess :: CreateProcess -> String -> m String Source #
Since: 0.1
Since: 0.1
readCreateProcessWithExitCode Source #
Arguments
| :: CreateProcess | . |
| -> String | |
| -> m (ExitCode, String, String) |
Since: 0.1
readProcessWithExitCode Source #
Since: 0.1
Arguments
| :: HasCallStack | |
| => CreateProcess | . |
| -> (Maybe Handle -> Maybe Handle -> Maybe Handle -> ProcessHandle -> m a) | |
| -> m a |
Since: 0.1
Since: 0.1
getPid :: ProcessHandle -> m (Maybe Pid) Source #
Since: 0.1
getCurrentPid :: m Pid Source #
Since: 0.1
waitForProcess :: ProcessHandle -> m ExitCode Source #
Since: 0.1
getProcessExitCode :: ProcessHandle -> m (Maybe ExitCode) Source #
Since: 0.1
terminateProcess :: ProcessHandle -> m () Source #
Since: 0.1
interruptProcessGroupOf :: ProcessHandle -> m () Source #
Since: 0.1
createPipe :: m (Handle, Handle) Source #
Since: 0.1
createPipeFd :: m (FD, FD) Source #
Since: 0.1
Instances
Running sub-processes
Arguments
| :: MonadProcess m | |
| => CreateProcess | . |
| -> m (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) |
Since: 0.1
Arguments
| :: MonadProcess m | |
| => String | . |
| -> CreateProcess | |
| -> m (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) |
Since: 0.1
shell :: String -> CreateProcess #
Construct a CreateProcess record for passing to createProcess,
representing a command to be passed to the shell.
proc :: FilePath -> [String] -> CreateProcess #
Construct a CreateProcess record for passing to createProcess,
representing a raw command with arguments.
See RawCommand for precise semantics of the specified FilePath.
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 Methods (==) :: CreateProcess -> CreateProcess -> Bool # (/=) :: CreateProcess -> CreateProcess -> Bool # | |
Constructors
| ShellCommand String | A command line to execute using the shell |
| RawCommand FilePath [String] | The name of an executable with a list of arguments The
Windows does not have a mechanism for passing multiple arguments.
When using |
Instances
| IsString CmdSpec # | construct a Since: process-1.2.1.0 |
Defined in System.Process.Common Methods fromString :: String -> CmdSpec # | |
| Show CmdSpec # | |
| Eq CmdSpec # | |
Constructors
| Inherit | Inherit Handle from parent |
| UseHandle Handle | Use the supplied Handle |
| CreatePipe | Create a new pipe. The returned
|
| NoStream | Close 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 |
Instances
data ProcessHandle #
A handle to a process, which can be used to wait for termination
of the process using waitForProcess.
None of the process-creation functions in this library wait for
termination: they all return a ProcessHandle which may be used
to wait for the process later.
On Windows a second wait method can be used to block for event completion. This requires two handles. A process job handle and a events handle to monitor.
Simpler functions for common tasks
callProcess :: MonadProcess m => FilePath -> [String] -> m () Source #
Since: 0.1
callCommand :: MonadProcess m => String -> m () Source #
Since: 0.1
spawnProcess :: MonadProcess m => FilePath -> [String] -> m ProcessHandle Source #
Since: 0.1
spawnCommand :: MonadProcess m => String -> m ProcessHandle Source #
Since: 0.1
readCreateProcess :: MonadProcess m => CreateProcess -> String -> m String Source #
Since: 0.1
Arguments
| :: MonadProcess m | |
| => FilePath | . |
| -> [String] | |
| -> String | |
| -> m String |
Since: 0.1
readCreateProcessWithExitCode Source #
Arguments
| :: MonadProcess m | |
| => CreateProcess | . |
| -> String | |
| -> m (ExitCode, String, String) |
Since: 0.1
readProcessWithExitCode Source #
Since: 0.1
Arguments
| :: (MonadProcess m, HasCallStack) | |
| => CreateProcess | . |
| -> (Maybe Handle -> Maybe Handle -> Maybe Handle -> ProcessHandle -> m a) | |
| -> m a |
Since: 0.1
Arguments
| :: MonadProcess m | |
| => (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) | . |
| -> m () |
Since: 0.1
Related utilities
showCommandForUser :: FilePath -> [String] -> String #
Given a program p and arguments args,
showCommandForUser p args returns a string suitable for pasting
into /bin/sh (on Unix systems) or CMD.EXE (on Windows).
The platform specific type for a process identifier.
This is always an integral type. Width and signedness are platform specific.
Since: process-1.6.3.0
getPid :: MonadProcess m => ProcessHandle -> m (Maybe Pid) Source #
Since: 0.1
getCurrentPid :: MonadProcess m => m Pid Source #
Since: 0.1
waitForProcess :: MonadProcess m => ProcessHandle -> m ExitCode Source #
Since: 0.1
getProcessExitCode :: MonadProcess m => ProcessHandle -> m (Maybe ExitCode) Source #
Since: 0.1
terminateProcess :: MonadProcess m => ProcessHandle -> m () Source #
Since: 0.1
interruptProcessGroupOf :: MonadProcess m => ProcessHandle -> m () Source #
Since: 0.1
createPipe :: MonadProcess m => m (Handle, Handle) Source #
Since: 0.1
createPipeFd :: MonadProcess m => m (FD, FD) Source #
Since: 0.1
Re-exports
Haskell defines operations to read and write characters from and to files,
represented by values of type Handle. Each value of this type is a
handle: a record used by the Haskell run-time system to manage I/O
with file system objects. A handle has at least the following properties:
- whether it manages input or output or both;
- whether it is open, closed or semi-closed;
- whether the object is seekable;
- whether buffering is disabled, or enabled on a line or block basis;
- a buffer (whose length may be zero).
Most handles will also have a current I/O position indicating where the next
input or output operation will occur. A handle is readable if it
manages only input or both input and output; likewise, it is writable if
it manages only output or both input and output. A handle is open when
first allocated.
Once it is closed it can no longer be used for either input or output,
though an implementation cannot re-use its storage while references
remain to it. Handles are in the Show and Eq classes. The string
produced by showing a handle is system dependent; it should include
enough information to identify the handle for debugging. A handle is
equal according to == only to itself; no attempt
is made to compare the internal state of different handles for equality.