Haskell Hierarchical Libraries (base package)ContentsIndex
System.Process
Portabilityportable
Stabilityexperimental
Maintainerlibraries@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
:: FilePathFilename of the executable
-> [String]Arguments to pass to the executable
-> Maybe FilePathOptional path to the working directory
-> Maybe [(String, String)]Optional environment (otherwise inherit)
-> Maybe HandleHandle to use for stdin
-> Maybe HandleHandle to use for stdout
-> Maybe HandleHandle to use for stderr
-> IO ProcessHandle

Runs a raw command, optionally specifying Handles from which to take the stdin, stdout and stderr channels for the new process.

Any Handles passed to runProcess are placed immediately in the closed state, so may no longer be referenced by the Haskell process.

runInteractiveCommand :: 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.
runInteractiveProcess
:: FilePathFilename of the executable
-> [String]Arguments to pass to the executable
-> Maybe FilePathOptional path to the working directory
-> Maybe [(String, String)]Optional environment (otherwise inherit)
-> IO (Handle, Handle, Handle, 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)
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)
Verifies whether the process is completed and if it is then returns the exit code. If the process is still running the function returns Nothing
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