Safe Haskell | None |
---|---|
Language | Haskell98 |
Support for running external tools. Written mainly for GHCi but with | support for others in mind.
- data ToolOutput
- toolline :: ToolOutput -> Text
- data ToolCommand = ToolCommand Text Text (Sink ToolOutput IO ())
- data ToolState = ToolState {}
- toolProcess :: ToolState -> IO ProcessHandle
- newToolState :: IO ToolState
- runTool :: MonadIO m => FilePath -> [Text] -> Maybe FilePath -> IO (Source m ToolOutput, ProcessHandle)
- runTool' :: FilePath -> [Text] -> Maybe FilePath -> IO ([ToolOutput], ProcessHandle)
- runInteractiveTool :: ToolState -> CommandLineReader -> FilePath -> [Text] -> Maybe FilePath -> IO ()
- newGhci :: FilePath -> Maybe Text -> [Text] -> Sink ToolOutput IO () -> IO ToolState
- newGhci' :: [Text] -> Sink ToolOutput IO () -> IO ToolState
- executeCommand :: ToolState -> Text -> Text -> Sink ToolOutput IO () -> IO ()
- executeGhciCommand :: ToolState -> Text -> Sink ToolOutput IO () -> IO ()
- quoteArg :: Text -> Text
- escapeQuotes :: Text -> Text
- runCommand :: String -> IO ProcessHandle
- waitForProcess :: ProcessHandle -> IO ExitCode
- interruptProcessGroupOf :: ProcessHandle -> IO ()
- data ProcessHandle :: *
- getProcessExitCode :: ProcessHandle -> IO (Maybe ExitCode)
- runInteractiveProcess :: FilePath -> [String] -> Maybe FilePath -> Maybe [(String, String)] -> IO (Handle, Handle, Handle, ProcessHandle)
- runProcess :: FilePath -> [String] -> Maybe FilePath -> Maybe [(String, String)] -> Maybe Handle -> Maybe Handle -> Maybe Handle -> IO ProcessHandle
- readProcessWithExitCode :: FilePath -> [String] -> String -> IO (ExitCode, String, String)
- terminateProcess :: ProcessHandle -> IO ()
Documentation
data ToolOutput Source
toolline :: ToolOutput -> Text Source
data ToolCommand Source
ToolCommand Text Text (Sink ToolOutput IO ()) |
runTool :: MonadIO m => FilePath -> [Text] -> Maybe FilePath -> IO (Source m ToolOutput, ProcessHandle) Source
runTool' :: FilePath -> [Text] -> Maybe FilePath -> IO ([ToolOutput], ProcessHandle) Source
runInteractiveTool :: ToolState -> CommandLineReader -> FilePath -> [Text] -> Maybe FilePath -> IO () Source
executeCommand :: ToolState -> Text -> Text -> Sink ToolOutput IO () -> IO () Source
executeGhciCommand :: ToolState -> Text -> Sink ToolOutput IO () -> IO () Source
escapeQuotes :: Text -> Text Source
runCommand :: String -> IO ProcessHandle
Runs a command using the shell.
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
.
(Since: 1.2.0.0) On Unix systems, a negative value
indicates that the child was terminated by signal ExitFailure
-signumsignum
.
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.
:: 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
data ProcessHandle :: *
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
is returned where Just
ee
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.
:: FilePath | Filename of the executable (see |
-> [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)
The Handle
s are initially in binary mode; if you need them to be
in text mode then use hSetBinaryMode
.
:: FilePath | Filename of the executable (see |
-> [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 |
-> Maybe Handle | Handle to use for |
-> Maybe Handle | Handle to use for |
-> IO ProcessHandle |
Runs a raw command, optionally specifying Handle
s from which to
take the stdin
, stdout
and stderr
channels for the new
process (otherwise these handles are inherited from the current
process).
Any Handle
s passed to runProcess
are placed immediately in the
closed state.
Note: consider using the more general createProcess
instead of
runProcess
.
:: FilePath | Filename of the executable (see |
-> [String] | any arguments |
-> String | standard input |
-> IO (ExitCode, String, String) | exitcode, stdout, stderr |
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.
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.