-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A replacement for System.Exit and System.Process. -- @package sys-process @version 0.1.3 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.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 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 instance Eq StdStream instance Show StdStream instance (Choice p, Applicative f) => AsCreatePipe p f StdStream instance AsCreatePipe p f () instance (Choice p, Applicative f) => AsUseHandle p f StdStream instance AsUseHandle p f Handle instance (Choice p, Applicative f) => AsInherit p f StdStream instance AsInherit p f () instance (Profunctor p, Functor f) => AsStdStream p f StdStream instance AsStdStream p f StdStream 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: -- -- 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 Eq CmdSpec instance Ord CmdSpec instance Show CmdSpec instance (Choice p, Applicative f) => AsRawCommand p f CmdSpec instance AsRawCommand p f (FilePath, [String]) instance (Choice p, Applicative f) => AsShellCommand p f CmdSpec instance AsShellCommand p f String instance Applicative f => AsExecutableArguments (->) f CmdSpec instance AsExecutableArguments p f [String] instance Applicative f => AsExecutableName (->) f CmdSpec instance AsExecutableName p f FilePath instance (Profunctor p, Functor f) => AsCmdSpec p f CmdSpec instance AsCmdSpec p f CmdSpec instance IsString CmdSpec module Sys.CreateProcess data CreateProcess CreateProcess :: CmdSpec -> (Maybe FilePath) -> (Maybe [(String, String)]) -> StdStream -> StdStream -> StdStream -> Bool -> Bool -> Bool -> 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 Eq CreateProcess instance Show CreateProcess instance Functor f => AsDelegateCtrlC (->) f CreateProcess instance AsDelegateCtrlC p f Bool instance Functor f => AsCreateGroup (->) f CreateProcess instance AsCreateGroup p f Bool instance Functor f => AsCloseDescriptors (->) f CreateProcess instance AsCloseDescriptors p f Bool instance Functor f => AsStderr (->) f CreateProcess instance AsStderr p f StdStream instance Functor f => AsStdout (->) f CreateProcess instance AsStdout p f StdStream instance Functor f => AsStdin (->) f CreateProcess instance AsStdin p f StdStream instance Functor f => AsEnvironment (->) f CreateProcess instance AsEnvironment p f (Maybe [(String, String)]) instance Functor f => AsWorkingDirectory (->) f CreateProcess instance AsWorkingDirectory p f (Maybe FilePath) instance Applicative f => AsRawCommand (->) f CreateProcess instance Applicative f => AsShellCommand (->) f CreateProcess instance Applicative f => AsExecutableArguments (->) f CreateProcess instance Applicative f => AsExecutableName (->) f CreateProcess instance Functor f => AsCmdSpec (->) f CreateProcess instance (Profunctor p, Functor f) => AsCreateProcess p f CreateProcess instance AsCreateProcess p f 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 -- -- -- -- 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: -- -- -- -- see createProcess_. createProcess_ :: String -> CreateProcess -> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) -- | 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 -- | 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: -- -- -- -- 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