| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Sys.Process
Contents
- createProcess :: CreateProcess -> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
- createProcess_ :: String -> CreateProcess -> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
- shell :: String -> CreateProcess
- proc :: FilePath -> [String] -> CreateProcess
- callProcess :: FilePath -> [String] -> IO ()
- callCommand :: String -> IO ()
- spawnProcess :: FilePath -> [String] -> IO ProcessHandle
- spawnCommand :: String -> IO ProcessHandle
- readCreateProcess :: CreateProcess -> String -> IO String
- readProcess :: FilePath -> [String] -> String -> IO String
- readCreateProcessWithExitCode :: CreateProcess -> String -> IO (ExitCode, String, String)
- readProcessWithExitCode :: FilePath -> [String] -> String -> IO (ExitCode, String, String)
- showCommandForUser :: FilePath -> [String] -> String
- waitForProcess :: ProcessHandle -> IO ExitCode
- getProcessExitCode :: ProcessHandle -> IO (Maybe ExitCode)
- terminateProcess :: ProcessHandle -> IO ()
- interruptProcessGroupOf :: ProcessHandle -> IO ()
- createPipe :: IO (Handle, Handle)
Running sub-processes
createProcess :: CreateProcess -> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) Source
createProcess_ :: String -> CreateProcess -> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) Source
shell :: String -> CreateProcess Source
proc :: FilePath -> [String] -> CreateProcess Source
Simpler functions for common tasks
callProcess :: FilePath -> [String] -> IO ()
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
callCommand :: 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
spawnProcess :: FilePath -> [String] -> IO ProcessHandle
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
spawnCommand :: 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
readCreateProcess :: CreateProcess -> String -> IO String Source
Arguments
| :: FilePath | Filename of the executable (see |
| -> [String] | any arguments |
| -> String | standard input |
| -> IO String | stdout |
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 interactive applications.
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:
- The command to run, which must be in the $PATH, or an absolute or relative path
- A list of separate command line arguments to the program
- A string to pass on standard input to the forked process.
readCreateProcessWithExitCode :: CreateProcess -> String -> IO (ExitCode, String, String) Source
Related utilities
showCommandForUser :: FilePath -> [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).
Control-C handling on Unix
getProcessExitCode :: ProcessHandle -> IO (Maybe ExitCode) Source
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 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.
Arguments
| :: ProcessHandle | A process in the process group |
| -> 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
Interprocess communication
createPipe :: IO (Handle, Handle)
Create a pipe for interprocess communication and return a
(readEnd, writeEnd) Handle pair.
Since: 1.2.1.0