-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | A replacement for System.Exit and System.Process.
--
--
-- A replacement for System.Exit and System.Process.
@package sys-process
@version 0.2.0
module Sys.StdStream
data StdStream
-- | Inherit Handle from parent
Inherit :: StdStream
-- | Use the supplied Handle
UseHandle :: Handle -> StdStream
-- | Create a new pipe. The returned Handle will use the default
-- encoding and newline translation mode (just like Handles
-- created by openFile).
CreatePipe :: StdStream
NoStream :: StdStream
class AsStdStream p f s
_StdStream :: AsStdStream p f s => Optic' p f s StdStream
class AsInherit p f s
_Inherit :: AsInherit p f s => Optic' p f s ()
class AsUseHandle p f s
_UseHandle :: AsUseHandle p f s => Optic' p f s Handle
class AsCreatePipe p f s
_CreatePipe :: AsCreatePipe p f s => Optic' p f s ()
class AsNoStream p f s
_NoStream :: AsNoStream p f s => Optic' p f s ()
instance GHC.Show.Show Sys.StdStream.StdStream
instance GHC.Classes.Eq Sys.StdStream.StdStream
instance Sys.StdStream.AsStdStream p f Sys.StdStream.StdStream
instance (Data.Profunctor.Unsafe.Profunctor p, GHC.Base.Functor f) => Sys.StdStream.AsStdStream p f System.Process.Common.StdStream
instance Sys.StdStream.AsInherit p f ()
instance (Data.Profunctor.Choice.Choice p, GHC.Base.Applicative f) => Sys.StdStream.AsInherit p f Sys.StdStream.StdStream
instance Sys.StdStream.AsUseHandle p f GHC.IO.Handle.Types.Handle
instance (Data.Profunctor.Choice.Choice p, GHC.Base.Applicative f) => Sys.StdStream.AsUseHandle p f Sys.StdStream.StdStream
instance Sys.StdStream.AsCreatePipe p f ()
instance (Data.Profunctor.Choice.Choice p, GHC.Base.Applicative f) => Sys.StdStream.AsCreatePipe p f Sys.StdStream.StdStream
instance Sys.StdStream.AsNoStream p f ()
instance (Data.Profunctor.Choice.Choice p, GHC.Base.Applicative f) => Sys.StdStream.AsNoStream p f Sys.StdStream.StdStream
module Sys.ExitCode
type ExitCode = Number Int
_ExitFailure :: Prism' ExitCode (NotZero Int)
_ExitSuccess :: Prism' ExitCode ()
exitFailure :: NotZero Int -> ExitCode
exitSuccess :: ExitCode
exitFailureP :: Prism' ExitCode Int
exitSuccessP :: Prism' ExitCode ()
exitCode :: ExitCode -> ExitCode
unExitCode :: ExitCode -> ExitCode
module Sys.CmdSpec
data CmdSpec
-- | A command line to execute using the shell
ShellCommand :: String -> CmdSpec
-- | The name of an executable with a list of arguments
--
-- The FilePath argument names the executable, and is interpreted
-- according to the platform's standard policy for searching for
-- executables. Specifically:
--
--
-- - on Unix systems the execvp(3) semantics is used, where if
-- the executable filename does not contain a slash (/) then the
-- PATH environment variable is searched for the
-- executable.
-- - on Windows systems the Win32 CreateProcess semantics is
-- used. Briefly: if the filename does not contain a path, then the
-- directory containing the parent executable is searched, followed by
-- the current directory, then some standard locations, and finally the
-- current PATH. An .exe extension is added if the
-- filename does not already have an extension. For full details see the
-- documentation for the Windows SearchPath API.
--
RawCommand :: FilePath -> [String] -> CmdSpec
class AsCmdSpec p f s
_CmdSpec :: AsCmdSpec p f s => Optic' p f s CmdSpec
class AsExecutableName p f s
_ExecutableName :: AsExecutableName p f s => Optic' p f s FilePath
class AsExecutableArguments p f s
_ExecutableArguments :: AsExecutableArguments p f s => Optic' p f s [String]
class AsShellCommand p f s
_ShellCommand :: AsShellCommand p f s => Optic' p f s String
class AsRawCommand p f s
_RawCommand :: AsRawCommand p f s => Optic' p f s (FilePath, [String])
instance GHC.Show.Show Sys.CmdSpec.CmdSpec
instance GHC.Classes.Ord Sys.CmdSpec.CmdSpec
instance GHC.Classes.Eq Sys.CmdSpec.CmdSpec
instance Data.String.IsString Sys.CmdSpec.CmdSpec
instance Sys.CmdSpec.AsCmdSpec p f Sys.CmdSpec.CmdSpec
instance (Data.Profunctor.Unsafe.Profunctor p, GHC.Base.Functor f) => Sys.CmdSpec.AsCmdSpec p f System.Process.Common.CmdSpec
instance Sys.CmdSpec.AsExecutableName p f GHC.IO.FilePath
instance GHC.Base.Applicative f => Sys.CmdSpec.AsExecutableName (->) f Sys.CmdSpec.CmdSpec
instance Sys.CmdSpec.AsExecutableArguments p f [GHC.Base.String]
instance GHC.Base.Applicative f => Sys.CmdSpec.AsExecutableArguments (->) f Sys.CmdSpec.CmdSpec
instance Sys.CmdSpec.AsShellCommand p f GHC.Base.String
instance (Data.Profunctor.Choice.Choice p, GHC.Base.Applicative f) => Sys.CmdSpec.AsShellCommand p f Sys.CmdSpec.CmdSpec
instance Sys.CmdSpec.AsRawCommand p f (GHC.IO.FilePath, [GHC.Base.String])
instance (Data.Profunctor.Choice.Choice p, GHC.Base.Applicative f) => Sys.CmdSpec.AsRawCommand p f Sys.CmdSpec.CmdSpec
module Sys.CreateProcess
-- | Data type representing a process.
--
-- see CreateProcess.
data CreateProcess
CreateProcess :: CmdSpec -> (Maybe FilePath) -> (Maybe [(String, String)]) -> StdStream -> StdStream -> StdStream -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> (Maybe GroupID) -> (Maybe UserID) -> CreateProcess
-- | Types that related to CreateProcess.
class AsCreateProcess p f s
_CreateProcess :: AsCreateProcess p f s => Optic' p f s CreateProcess
-- | Types that relate to a (maybe) working directory.
class AsWorkingDirectory p f s
_WorkingDirectory :: AsWorkingDirectory p f s => Optic' p f s (Maybe FilePath)
-- | Types that relate to an environment.
class AsEnvironment p f s
_Environment :: AsEnvironment p f s => Optic' p f s (Maybe [(String, String)])
-- | Types that relate to a standard input stream.
class AsStdin p f s
_Stdin :: AsStdin p f s => Optic' p f s StdStream
-- | Types that relate to a standard output stream.
class AsStdout p f s
_Stdout :: AsStdout p f s => Optic' p f s StdStream
-- | Types that relate to a standard error stream.
class AsStderr p f s
_Stderr :: AsStderr p f s => Optic' p f s StdStream
-- | Types that relate to closing descriptors.
class AsCloseDescriptors p f s
_CloseDescriptors :: AsCloseDescriptors p f s => Optic' p f s Bool
-- | Types that relate to creating groups.
class AsCreateGroup p f s
_CreateGroup :: AsCreateGroup p f s => Optic' p f s Bool
-- | Types that relate to delegating CTRL-C.
class AsDelegateCtrlC p f s
_DelegateCtrlC :: AsDelegateCtrlC p f s => Optic' p f s Bool
instance GHC.Show.Show Sys.CreateProcess.CreateProcess
instance GHC.Classes.Eq Sys.CreateProcess.CreateProcess
instance Sys.CreateProcess.AsCreateProcess p f Sys.CreateProcess.CreateProcess
instance (Data.Profunctor.Unsafe.Profunctor p, GHC.Base.Functor f) => Sys.CreateProcess.AsCreateProcess p f System.Process.Common.CreateProcess
instance GHC.Base.Functor f => Sys.CmdSpec.AsCmdSpec (->) f Sys.CreateProcess.CreateProcess
instance GHC.Base.Applicative f => Sys.CmdSpec.AsExecutableName (->) f Sys.CreateProcess.CreateProcess
instance GHC.Base.Applicative f => Sys.CmdSpec.AsExecutableArguments (->) f Sys.CreateProcess.CreateProcess
instance GHC.Base.Applicative f => Sys.CmdSpec.AsShellCommand (->) f Sys.CreateProcess.CreateProcess
instance GHC.Base.Applicative f => Sys.CmdSpec.AsRawCommand (->) f Sys.CreateProcess.CreateProcess
instance Sys.CreateProcess.AsWorkingDirectory p f (GHC.Base.Maybe GHC.IO.FilePath)
instance GHC.Base.Functor f => Sys.CreateProcess.AsWorkingDirectory (->) f Sys.CreateProcess.CreateProcess
instance Sys.CreateProcess.AsEnvironment p f (GHC.Base.Maybe [(GHC.Base.String, GHC.Base.String)])
instance GHC.Base.Functor f => Sys.CreateProcess.AsEnvironment (->) f Sys.CreateProcess.CreateProcess
instance Sys.CreateProcess.AsStdin p f Sys.StdStream.StdStream
instance GHC.Base.Functor f => Sys.CreateProcess.AsStdin (->) f Sys.CreateProcess.CreateProcess
instance Sys.CreateProcess.AsStdout p f Sys.StdStream.StdStream
instance GHC.Base.Functor f => Sys.CreateProcess.AsStdout (->) f Sys.CreateProcess.CreateProcess
instance Sys.CreateProcess.AsStderr p f Sys.StdStream.StdStream
instance GHC.Base.Functor f => Sys.CreateProcess.AsStderr (->) f Sys.CreateProcess.CreateProcess
instance Sys.CreateProcess.AsCloseDescriptors p f GHC.Types.Bool
instance GHC.Base.Functor f => Sys.CreateProcess.AsCloseDescriptors (->) f Sys.CreateProcess.CreateProcess
instance Sys.CreateProcess.AsCreateGroup p f GHC.Types.Bool
instance GHC.Base.Functor f => Sys.CreateProcess.AsCreateGroup (->) f Sys.CreateProcess.CreateProcess
instance Sys.CreateProcess.AsDelegateCtrlC p f GHC.Types.Bool
instance GHC.Base.Functor f => Sys.CreateProcess.AsDelegateCtrlC (->) f Sys.CreateProcess.CreateProcess
module Sys.Process
data ProcessHandle :: *
-- | This is the most general way to spawn an external process. The process
-- can be a command line to be executed by a shell or a raw command with
-- a list of arguments. The stdin, stdout, and stderr streams of the new
-- process may individually be attached to new pipes, to existing
-- Handles, or just inherited from the parent (the default.)
--
-- The details of how to create the process are passed in the
-- CreateProcess record. To make it easier to construct a
-- CreateProcess, the functions proc and shell are
-- supplied that fill in the fields with default values which can be
-- overriden as needed.
--
-- createProcess returns (mb_stdin_hdl,
-- mb_stdout_hdl, mb_stderr_hdl, ph), where
--
--
-- - if std_in == CreatePipe, then
-- mb_stdin_hdl will be Just h, where
-- h is the write end of the pipe connected to the child
-- process's stdin.
-- - otherwise, mb_stdin_hdl == Nothing
--
--
-- Similarly for mb_stdout_hdl and
-- mb_stderr_hdl.
--
-- For example, to execute a simple ls command:
--
--
-- r <- createProcess (proc "ls" [])
--
--
-- To create a pipe from which to read the output of ls:
--
--
-- (_, Just hout, _, _) <-
-- createProcess (proc "ls" []){ std_out = CreatePipe }
--
--
-- To also set the directory in which to run ls:
--
--
-- (_, Just hout, _, _) <-
-- createProcess (proc "ls" []){ cwd = Just "\home\bob",
-- std_out = CreatePipe }
--
--
-- Note that Handles provided for std_in,
-- std_out, or std_err via the UseHandle
-- constructor will be closed by calling this function. This is not
-- always the desired behavior. In cases where you would like to leave
-- the Handle open after spawning the child process, please use
-- createProcess_ instead.
--
-- see createProcess.
createProcess :: CreateProcess -> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
-- | This function is almost identical to createProcess. The only
-- differences are:
--
--
-- - Handles provided via UseHandle are not closed
-- automatically.
-- - This function takes an extra String argument to be used
-- in creating error messages.
--
--
-- see createProcess_.
createProcess_ :: String -> CreateProcess -> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
createProcessHandle :: CreateProcess -> IO ProcessHandle
createWaitProcess :: CreateProcess -> IO ExitCode
createMakeWaitProcess :: CreateProcess -> IO ExitCode
-- | Construct a CreateProcess record for passing to
-- createProcess, representing a command to be passed to the
-- shell.
--
-- see shell.
shell :: 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.
--
-- see proc.
proc :: FilePath -> [String] -> CreateProcess
procIn :: FilePath -> FilePath -> [String] -> CreateProcess
-- | Creates a new process to run the specified command with the given
-- arguments, and wait for it to finish. If the command returns a
-- non-zero exit code, an exception is raised.
--
-- If an asynchronous exception is thrown to the thread executing
-- callProcess. The forked process will be terminated and
-- callProcess will wait (block) until the process has been
-- terminated.
--
-- see 'System.Process.callProcess.
callProcess :: FilePath -> [String] -> IO ()
-- | Creates a new process to run the specified shell command. If the
-- command returns a non-zero exit code, an exception is raised.
--
-- If an asynchronous exception is thrown to the thread executing
-- callCommand. The forked process will be terminated and
-- callCommand will wait (block) until the process has been
-- terminated.
--
-- see 'System.Process.callCommand.
callCommand :: String -> IO ()
-- | Creates a new process to run the specified raw command with the given
-- arguments. It does not wait for the program to finish, but returns the
-- ProcessHandle.
--
-- see 'System.Process.spawnProcess.
spawnProcess :: FilePath -> [String] -> IO ProcessHandle
-- | Creates a new process to run the specified shell command. It does not
-- wait for the program to finish, but returns the
-- ProcessHandle.
--
-- see 'System.Process.spawnCommand.
spawnCommand :: String -> IO ProcessHandle
-- | readCreateProcess works exactly like readProcess
-- except that it lets you pass CreateProcess giving better
-- flexibility.
--
--
-- > readCreateProcess (shell "pwd" { cwd = "/etc/" }) ""
-- "/etc\n"
--
--
-- Note that Handles provided for std_in or
-- std_out via the CreateProcess record will be ignored.
--
-- see readCreateProcess.
readCreateProcess :: CreateProcess -> String -> IO String
readProcess :: FilePath -> [String] -> String -> IO String
-- | readCreateProcessWithExitCode works exactly like
-- readProcessWithExitCode except that it lets you pass
-- CreateProcess giving better flexibility.
--
-- Note that Handles provided for std_in,
-- std_out, or std_err via the CreateProcess record
-- will be ignored.
--
-- see readCreateProcessWithExitCode.
readCreateProcessWithExitCode :: CreateProcess -> String -> IO (ExitCode, String, String)
-- | readProcessWithExitCode is like readProcess but with
-- two differences:
--
--
-- - it returns the ExitCode of the process, and does not throw
-- any exception if the code is not ExitSuccess.
-- - it reads and returns the output from process' standard error
-- handle, rather than the process inheriting the standard error
-- handle.
--
--
-- On Unix systems, see waitForProcess for the meaning of exit
-- codes when the process died as the result of a signal.
--
-- see readProcessWithExitCode.
readProcessWithExitCode :: FilePath -> [String] -> String -> IO (ExitCode, 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).
--
-- see showCommandForUser.
showCommandForUser :: FilePath -> [String] -> String
-- | Waits for the specified process to terminate, and returns its exit
-- code.
--
-- GHC Note: in order to call waitForProcess without blocking
-- all the other threads in the system, you must compile the program with
-- -threaded.
--
-- On Unix systems, a negative value ExitFailure
-- -signum indicates that the child was terminated by signal
-- signum. The signal numbers are platform-specific, so
-- to test for a specific signal use the constants provided by
-- System.Posix.Signals in the unix package. Note: core
-- dumps are not reported, use System.Posix.Process if you need
-- this detail.
--
-- see waitForProcess.
waitForProcess :: ProcessHandle -> IO ExitCode
-- | This is a non-blocking version of waitForProcess. If the
-- process is still running, Nothing is returned. If the process
-- has exited, then Just e is returned where e
-- is the exit code of the process.
--
-- On Unix systems, see waitForProcess for the meaning of exit
-- codes when the process died as the result of a signal.
--
-- see getProcessExitCode.
getProcessExitCode :: ProcessHandle -> IO (Maybe ExitCode)
-- | Attempts to terminate the specified process. This function should not
-- be used under normal circumstances - no guarantees are given regarding
-- how cleanly the process is terminated. To check whether the process
-- has indeed terminated, use getProcessExitCode.
--
-- On Unix systems, terminateProcess sends the process the SIGTERM
-- signal. On Windows systems, the Win32 TerminateProcess
-- function is called, passing an exit code of 1.
--
-- Note: on Windows, if the process was a shell command created by
-- createProcess with shell, or created by
-- runCommand or runInteractiveCommand, then
-- terminateProcess will only terminate the shell, not the command
-- itself. On Unix systems, both processes are in a process group and
-- will be terminated together.
--
-- see 'System.Process.terminateProcess.
terminateProcess :: ProcessHandle -> IO ()
-- | Sends an interrupt signal to the process group of the given process.
--
-- On Unix systems, it sends the group the SIGINT signal.
--
-- On Windows systems, it generates a CTRL_BREAK_EVENT and will only work
-- for processes created using createProcess and setting the
-- create_group flag
--
-- see 'System.Process.interruptProcessGroupOf.
interruptProcessGroupOf :: ProcessHandle -> IO ()
-- | Create a pipe for interprocess communication and return a
-- (readEnd, writeEnd) Handle pair.
--
-- see createPipe.
createPipe :: IO (Handle, Handle)
module Sys.Exit
-- | Computation exitWith code throws ExitCode
-- code. Normally this terminates the program, returning
-- code to the program's caller.
--
-- On program termination, the standard Handles stdout
-- and stderr are flushed automatically; any other buffered
-- Handles need to be flushed manually, otherwise the buffered
-- data will be discarded.
--
-- A program that fails in any other way is treated as if it had called
-- exitFailure. A program that terminates successfully without
-- calling exitWith explicitly is treated as it it had called
-- exitWith ExitSuccess.
--
-- As an ExitCode is not an IOError, exitWith
-- bypasses the error handling in the IO monad and cannot be
-- intercepted by catch from the Prelude. However it is a
-- SomeException, and can be caught using the functions of
-- Control.Exception. This means that cleanup computations added
-- with bracket (from Control.Exception) are also executed
-- properly on exitWith.
--
-- Note: in GHC, exitWith should be called from the main program
-- thread in order to exit the process. When called from another thread,
-- exitWith will throw an ExitException as normal, but
-- the exception will not cause the process itself to exit.
--
-- see 'System.Exit.exitWith.
exitWith :: ExitCode -> IO a
exitWithFailure :: NotZero Int -> IO a
-- | The computation exitWithFailure1 is equivalent to
-- exitWith (ExitFailure
-- exitfail), where exitfail is
-- implementation-dependent.
--
-- see 'System.Exit.exitWithFailure.
exitWithFailure1 :: IO a
-- | The computation exitWithSuccess is equivalent to
-- exitWith ExitSuccess, It terminates the program
-- successfully.
--
-- see 'System.Exit.exitWithSuccess.
exitWithSuccess :: IO a
type ExitCodeM f = NotZeroOrT Int f ()
exitCodeM :: f (Number Int) -> ExitCodeM f
createWaitProcessM :: CreateProcess -> ExitCodeM IO
createMakeWaitProcessM :: CreateProcess -> ExitCodeM IO
createWaitProcesses :: Foldable t => t CreateProcess -> ExitCodeM IO
createMakeWaitProcesses :: Foldable t => t CreateProcess -> ExitCodeM IO
exit :: ExitCodeM IO -> IO ()
createWaitProcessesExit :: Foldable t => t CreateProcess -> IO ()
createMakeWaitProcessesExit :: Foldable t => t CreateProcess -> IO ()