-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Process libraries
--
-- This package contains libraries for dealing with system processes.
@package process
@version 1.2.0.0
-- | 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
--
--
-- - 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 }
--
createProcess :: 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.
shell :: String -> CreateProcess
-- | Construct a CreateProcess record for passing to
-- createProcess, representing a raw command with 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.
--
proc :: FilePath -> [String] -> CreateProcess
data CreateProcess
CreateProcess :: CmdSpec -> Maybe FilePath -> Maybe [(String, String)] -> StdStream -> StdStream -> StdStream -> Bool -> Bool -> Bool -> CreateProcess
-- | Executable & arguments, or shell command
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)
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.
--
-- Since: 1.2.0.0
delegate_ctlc :: CreateProcess -> Bool
data CmdSpec
-- | a command line to execute using the shell
ShellCommand :: String -> CmdSpec
-- | the filename of an executable with a list of arguments. see
-- proc for the precise interpretation of the FilePath
-- field.
RawCommand :: FilePath -> [String] -> CmdSpec
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
data ProcessHandle
-- | 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.
--
-- Since: 1.2.0.0
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.
--
-- Since: 1.2.0.0
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.
--
-- Since: 1.2.0.0
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.
--
-- Since: 1.2.0.0
spawnCommand :: String -> IO ProcessHandle
-- | readProcess forks an external process, reads its standard
-- output strictly, blocking until the process terminates, and returns
-- the output string.
--
-- 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 interactive
-- applications.
--
-- This function throws an IOError if the process ExitCode
-- is anything other than ExitSuccess.
--
-- 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:
--
--
-- - The command to run, which must be in the $PATH, or an absolute
-- path
-- - A list of separate command line arguments to the program
-- - A string to pass on the standard input to the program.
--
readProcess :: FilePath -> [String] -> String -> IO String
-- | readProcessWithExitCode creates an external process, reads
-- its standard output and standard error strictly, waits until the
-- process terminates, and then returns the ExitCode of the
-- process, the standard output, and the standard error.
--
-- If an asynchronous exception is thrown to the thread executing
-- readProcessWithExitCode. The forked process will be
-- terminated and readProcessWithExitCode will wait (block)
-- until the process has been terminated.
--
-- readProcess and readProcessWithExitCode are fairly
-- simple wrappers around createProcess. Constructing variants of
-- these functions is quite easy: follow the link to the source code to
-- see how readProcess is implemented.
--
-- On Unix systems, see waitForProcess for the meaning of exit
-- codes when the process died as the result of a signal.
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).
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.
--
-- (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.
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.
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 ()
-- | 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)
--
--
-- The Handles are initially in binary mode; if you need them to
-- be in text mode then use hSetBinaryMode.
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. The Handles
-- are initially in binary mode; if you need them to be in text mode then
-- use hSetBinaryMode.
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:
--
--
-- - PermissionDenied The process has insufficient
-- privileges to perform the operation.
-- - ResourceExhausted Insufficient resources are
-- available to perform the operation.
-- - UnsupportedOperation The implementation does not
-- support system calls.
--
--
-- On Windows, system passes the command to the Windows command
-- interpreter (CMD.EXE or COMMAND.COM), hence Unixy
-- shell tricks will not work.
--
-- On Unix systems, see waitForProcess for the meaning of exit
-- codes when the process died as the result of a signal.
system :: String -> IO ExitCode
-- | The computation rawSystem cmd args runs
-- the operating system command cmd in such a way that it
-- receives as arguments the args strings exactly as
-- given, with no funny escaping or shell meta-syntax expansion. It will
-- therefore behave more portably between operating systems than
-- system.
--
-- The return codes and possible failures are the same as for
-- system.
rawSystem :: String -> [String] -> IO ExitCode
-- | Executing an external command.
--
-- This module provides a simple interface for executing external
-- commands. For a more complex, but more powerful, interface, see the
-- System.Process module.
-- | Deprecated: Use System.Process instead
module System.Cmd
-- | 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:
--
--
-- - PermissionDenied The process has insufficient
-- privileges to perform the operation.
-- - ResourceExhausted Insufficient resources are
-- available to perform the operation.
-- - UnsupportedOperation The implementation does not
-- support system calls.
--
--
-- On Windows, system passes the command to the Windows command
-- interpreter (CMD.EXE or COMMAND.COM), hence Unixy
-- shell tricks will not work.
--
-- On Unix systems, see waitForProcess for the meaning of exit
-- codes when the process died as the result of a signal.
system :: String -> IO ExitCode
-- | The computation rawSystem cmd args runs
-- the operating system command cmd in such a way that it
-- receives as arguments the args strings exactly as
-- given, with no funny escaping or shell meta-syntax expansion. It will
-- therefore behave more portably between operating systems than
-- system.
--
-- The return codes and possible failures are the same as for
-- system.
rawSystem :: String -> [String] -> IO ExitCode