-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Process libraries -- -- This package contains libraries for dealing with system processes. -- -- The typed-process package is a more recent take on a process API, -- which uses this package internally. It features better binary support, -- easier concurrency, and a more composable API. You can read more about -- it at https://github.com/fpco/typed-process/#readme. @package process @version 1.6.16.0 -- | Note: This module exports internal implementation details that -- may change anytime. If you want a more stable API, use -- System.Process instead. module System.Process.Internals -- | 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. data ProcessHandle ProcessHandle :: !MVar ProcessHandle__ -> !Bool -> !MVar () -> ProcessHandle [phandle] :: ProcessHandle -> !MVar ProcessHandle__ [mb_delegate_ctlc] :: ProcessHandle -> !Bool [waitpidLock] :: ProcessHandle -> !MVar () data ProcessHandle__ OpenHandle :: PHANDLE -> ProcessHandle__ -- | the process [phdlProcessHandle] :: ProcessHandle__ -> PHANDLE OpenExtHandle :: PHANDLE -> PHANDLE -> ProcessHandle__ -- | the process [phdlProcessHandle] :: ProcessHandle__ -> PHANDLE -- | the job containing the process and its subprocesses [phdlJobHandle] :: ProcessHandle__ -> PHANDLE ClosedHandle :: ExitCode -> ProcessHandle__ type PHANDLE = CPid closePHANDLE :: PHANDLE -> IO () mkProcessHandle :: PHANDLE -> Bool -> IO ProcessHandle data CGid type GroupID = CGid type UserID = CUid modifyProcessHandle :: ProcessHandle -> (ProcessHandle__ -> IO (ProcessHandle__, a)) -> IO a withProcessHandle :: ProcessHandle -> (ProcessHandle__ -> IO a) -> IO a data CreateProcess CreateProcess :: CmdSpec -> Maybe FilePath -> Maybe [(String, String)] -> StdStream -> StdStream -> StdStream -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Maybe GroupID -> Maybe UserID -> Bool -> CreateProcess -- | Executable & arguments, or shell command. If cwd is -- Nothing, relative paths are resolved with respect to the -- current working directory. If cwd is provided, it is -- implementation-dependent whether relative paths are resolved with -- respect to cwd or the current working directory, so absolute -- paths should be used to ensure portability. [cmdspec] :: CreateProcess -> CmdSpec -- | Optional path to the working directory for the new process [cwd] :: CreateProcess -> Maybe FilePath -- | Optional environment (otherwise inherit from the current process) [env] :: CreateProcess -> Maybe [(String, String)] -- | How to determine stdin [std_in] :: CreateProcess -> StdStream -- | How to determine stdout [std_out] :: CreateProcess -> StdStream -- | How to determine stderr [std_err] :: CreateProcess -> StdStream -- | Close all file descriptors except stdin, stdout and stderr in the new -- process (on Windows, only works if std_in, std_out, and std_err are -- all Inherit). This implementation will call close an every fd from 3 -- to the maximum of open files, which can be slow for high maximum of -- open files. [close_fds] :: CreateProcess -> Bool -- | Create a new process group [create_group] :: CreateProcess -> Bool -- | Delegate control-C handling. Use this for interactive console -- processes to let them handle control-C themselves (see below for -- details). -- -- On Windows this has no effect. [delegate_ctlc] :: CreateProcess -> Bool -- | Use the windows DETACHED_PROCESS flag when creating the process; does -- nothing on other platforms. [detach_console] :: CreateProcess -> Bool -- | Use the windows CREATE_NEW_CONSOLE flag when creating the process; -- does nothing on other platforms. -- -- Default: False [create_new_console] :: CreateProcess -> Bool -- | Use posix setsid to start the new process in a new session; does -- nothing on other platforms. [new_session] :: CreateProcess -> Bool -- | Use posix setgid to set child process's group id; does nothing on -- other platforms. -- -- Default: Nothing [child_group] :: CreateProcess -> Maybe GroupID -- | Use posix setuid to set child process's user id; does nothing on other -- platforms. -- -- Default: Nothing [child_user] :: CreateProcess -> Maybe UserID -- | On Windows systems this flag indicates that we should wait for the -- entire process tree to finish before unblocking. On POSIX systems this -- flag is ignored. See $exec-on-windows for details. -- -- Default: False [use_process_jobs] :: CreateProcess -> Bool 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: -- --
-- #if defined(IO_MANAGER_WINIO) -- import GHC.IO.SubSystem ((!)) -- import GHC.IO.Handle.Windows (handleToHANDLE) -- import GHC.Event.Windows (associateHandle') -- #endif -- -- ... -- -- #if defined (IO_MANAGER_WINIO) -- return () ! (do -- associateHandle' =handleToHANDLE <handle) -- #endif ---- -- Only associate handles that you are in charge of read/writing to. Do -- not associate handles passed to another process. It's the process's -- reponsibility to register the handle if it supports async access. createPipe :: IO (Handle, Handle) -- | Create a pipe for interprocess communication and return a -- (readEnd, writeEnd) FD pair. createPipeFd :: IO (FD, FD) -- | 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 interruptProcessGroupOf :: ProcessHandle -> IO () -- | Operations for creating and interacting with sub-processes. module System.Process -- | 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 -- --
-- 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. All created Handles are
-- initially in text mode; if you need them to be in binary mode then use
-- hSetBinaryMode.
--
-- ph contains a handle to the running process. On
-- Windows use_process_jobs can be set in CreateProcess in order
-- to create a Win32 Job object to monitor a process tree's progress. If
-- it is set then that job is also returned inside ph.
-- ph can be used to kill all running sub-processes. This
-- feature has been available since 1.5.0.0.
createProcess :: CreateProcess -> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
-- | This function is almost identical to createProcess. The only
-- differences are:
--
--
-- > readCreateProcess ((shell "pwd") { cwd = Just "/etc/" }) ""
-- "/etc\n"
--
--
-- Note that Handles provided for std_in or
-- std_out via the CreateProcess record will be ignored.
readCreateProcess :: CreateProcess -> String -> IO String
-- | readProcess forks an external process, reads its standard
-- output strictly, blocking until the process terminates, and returns
-- the output string. The external process inherits the standard error.
--
-- If an asynchronous exception is thrown to the thread executing
-- readProcess, the forked process will be terminated and
-- readProcess will wait (block) until the process has been
-- terminated.
--
-- Output is returned strictly, so this is not suitable for launching
-- processes that require interaction over the standard file streams.
--
-- This function throws an IOError if the process ExitCode
-- is anything other than ExitSuccess. If instead you want to get
-- the ExitCode then use readProcessWithExitCode.
--
-- Users of this function should compile with -threaded if they
-- want other Haskell threads to keep running while waiting on the result
-- of readProcess.
--
-- -- > readProcess "date" [] [] -- "Thu Feb 7 10:03:39 PST 2008\n" ---- -- The arguments are: -- --
-- withCreateProcess (proc cmd args) { ... } $ \stdin stdout stderr ph -> do
-- ...
--
withCreateProcess :: CreateProcess -> (Maybe Handle -> Maybe Handle -> Maybe Handle -> ProcessHandle -> IO a) -> IO a
-- | Cleans up the process.
--
-- This function is meant to be invoked from any application level
-- cleanup handler. It terminates the process, and closes any
-- CreatePipe handles.
cleanupProcess :: (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) -> IO ()
-- | 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).
showCommandForUser :: FilePath -> [String] -> String
-- | The platform specific type for a process identifier.
--
-- This is always an integral type. Width and signedness are platform
-- specific.
type Pid = CPid
-- | Returns the PID (process ID) of a subprocess.
--
-- Nothing is returned if the handle 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.
getPid :: ProcessHandle -> IO (Maybe Pid)
-- | Returns the PID (process ID) of the current process. On POSIX systems,
-- this calls getProcessID from System.Posix.Process in the
-- unix package. On Windows, this calls
-- getCurrentProcessId from System.Win32.Process in the
-- Win32 package.
getCurrentPid :: IO Pid
-- | Waits for the specified process to terminate, and returns its exit
-- code. On Unix systems, may throw UserInterrupt when using
-- delegate_ctlc.
--
-- GHC Note: in order to call waitForProcess without blocking
-- all the other threads in the system, you must compile the program with
-- -threaded.
--
-- Note that it is safe to call waitForProcess for the same
-- process in multiple threads. When the process ends, threads blocking
-- on this call will wake in FIFO order. When using delegate_ctlc
-- and the process is interrupted, only the first waiting thread will
-- throw UserInterrupt.
--
-- (Since: 1.2.0.0) 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.
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. May throw
-- UserInterrupt when using delegate_ctlc.
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, if use_process_jobs is True
-- then the Win32 TerminateJobObject function is called to kill
-- all processes associated with the job and passing the exit code of 1
-- to each of them. Otherwise if use_process_jobs is False
-- then 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.
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
interruptProcessGroupOf :: ProcessHandle -> IO ()
-- | Create a pipe for interprocess communication and return a
-- (readEnd, writeEnd) Handle pair.
--
-- -- #if defined(IO_MANAGER_WINIO) -- import GHC.IO.SubSystem ((!)) -- import GHC.IO.Handle.Windows (handleToHANDLE) -- import GHC.Event.Windows (associateHandle') -- #endif -- -- ... -- -- #if defined (IO_MANAGER_WINIO) -- return () ! (do -- associateHandle' =handleToHANDLE <handle) -- #endif ---- -- Only associate handles that you are in charge of read/writing to. Do -- not associate handles passed to another process. It's the process's -- reponsibility to register the handle if it supports async access. createPipe :: IO (Handle, Handle) -- | Create a pipe for interprocess communication and return a -- (readEnd, writeEnd) FD pair. createPipeFd :: IO (FD, FD) -- | Runs a raw command, optionally specifying Handles from which to -- take the stdin, stdout and stderr channels -- for the new process (otherwise these handles are inherited from the -- current process). -- -- Any Handles passed to runProcess are placed immediately -- in the closed state. -- -- Note: consider using the more general createProcess instead of -- runProcess. runProcess :: FilePath -> [String] -> Maybe FilePath -> Maybe [(String, String)] -> Maybe Handle -> Maybe Handle -> Maybe Handle -> IO ProcessHandle -- | Runs a command using the shell. runCommand :: String -> IO ProcessHandle -- | Runs a raw command, and returns Handles that may be used to -- communicate with the process via its stdin, stdout -- and stderr respectively. -- -- For example, to start a process and feed a string to its stdin: -- --
-- (inp,out,err,pid) <- runInteractiveProcess "..." -- forkIO (hPutStr inp str) --runInteractiveProcess :: FilePath -> [String] -> Maybe FilePath -> Maybe [(String, String)] -> IO (Handle, Handle, Handle, ProcessHandle) -- | Runs a command using the shell, and returns Handles that may be -- used to communicate with the process via its stdin, -- stdout, and stderr respectively. runInteractiveCommand :: String -> IO (Handle, Handle, Handle, ProcessHandle) -- | Computation system cmd returns the exit code produced when -- the operating system runs the shell command cmd. -- -- This computation may fail with one of the following IOErrorType -- exceptions: -- --