leksah-server-0.14.3.2: Metadata collection for leksah

Safe HaskellNone
LanguageHaskell98

IDE.Utils.Tool

Description

Support for running external tools. Written mainly for GHCi but with | support for others in mind.

Synopsis

Documentation

runInteractiveTool :: ToolState -> CommandLineReader -> FilePath -> [Text] -> Maybe FilePath -> IO () 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 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.

interruptProcessGroupOf

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

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 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.

runInteractiveProcess

Arguments

:: FilePath

Filename of the executable (see proc for details)

-> [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 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.

runProcess

Arguments

:: FilePath

Filename of the executable (see proc for details)

-> [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 (Nothing => use existing stdin)

-> Maybe Handle

Handle to use for stdout (Nothing => use existing stdout)

-> Maybe Handle

Handle to use for stderr (Nothing => use existing stderr)

-> IO ProcessHandle 

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.

readProcessWithExitCode

Arguments

:: FilePath

Filename of the executable (see proc for details)

-> [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.