| Haskell Hierarchical Libraries (base package) | Contents | Index

System.Process

Portability | portable
Stability | experimental
Maintainer | libraries@haskell.org

Contents

Running sub-processes
Process completion

Description
Operations for creating and interacting with sub-processes.
Synopsis

data ProcessHandle
runCommand :: String -> IO ProcessHandle
runProcess :: FilePath -> [String] -> Maybe FilePath -> Maybe [(String, String)] -> Maybe Handle -> Maybe Handle -> Maybe Handle -> IO ProcessHandle
runInteractiveCommand :: String -> IO (Handle, Handle, Handle, ProcessHandle)
runInteractiveProcess :: FilePath -> [String] -> Maybe FilePath -> Maybe [(String, String)] -> IO (Handle, Handle, Handle, ProcessHandle)
waitForProcess :: ProcessHandle -> IO ExitCode
getProcessExitCode :: ProcessHandle -> IO (Maybe ExitCode)
terminateProcess :: ProcessHandle -> IO ()

Running sub-processes
data ProcessHandle

runCommand :: String -> IO ProcessHandle
Runs a command using the shell.
runProcess

:: FilePath | Filename of the executable
-> [String] | Arguments to pass to the executable
-> Maybe FilePath | Optional path to the working directory
-> Maybe [(String, String)] | Optional environment (otherwise inherit)
-> Maybe Handle | Handle to use for `stdin`
-> Maybe Handle | Handle to use for `stdout`
-> Maybe Handle | Handle to use for `stderr`
-> IO ProcessHandle |
Runs a raw command, optionally specifying `Handle`s from which to take the `stdin`, `stdout` and `stderr` channels for the new process. Any `Handle`s passed to `runProcess` are placed immediately in the closed state.

runInteractiveCommand :: String -> IO (Handle, Handle, Handle, ProcessHandle)
Runs a command using the shell, and returns `Handle`s that may be used to communicate with the process via its `stdin`, `stdout`, and `stderr` respectively.
runInteractiveProcess

:: FilePath | Filename of the executable
-> [String] | Arguments to pass to the executable
-> Maybe FilePath | Optional path to the working directory
-> Maybe [(String, String)] | Optional environment (otherwise inherit)
-> IO (Handle, Handle, Handle, ProcessHandle) |

Runs a raw command, and returns `Handle`s 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)

Process completion
waitForProcess :: ProcessHandle -> IO ExitCode
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`.
getProcessExitCode :: ProcessHandle -> IO (Maybe 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. Subsequent calls to `getProcessExitStatus` always return ``Just` `ExitSuccess``, regardless of what the original exit code was.
terminateProcess :: ProcessHandle -> IO ()

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 SIGKILL signal. On Windows systems, the Win32 `TerminateProcess` function is called, passing an exit code of 1.

Produced by Haddock version 0.7