| ||||||||||||||||||||
| ||||||||||||||||||||
| ||||||||||||||||||||
Description | ||||||||||||||||||||
Command invocation utilities. Written by John Goerzen, jgoerzen@complete.org Please note: Most of this module is not compatible with Hugs. Command lines executed will be logged using System.Log.Logger at the DEBUG level. Failure messages will be logged at the WARNING level in addition to being raised as an exception. Both are logged under "System.Cmd.Utils.funcname" -- for instance, "System.Cmd.Utils.safeSystem". If you wish to suppress these messages globally, you can simply run: updateGlobalLogger "System.Cmd.Utils.safeSystem" (setLevel CRITICAL) See also: updateGlobalLogger, System.Log.Logger. It is possible to set up pipelines with these utilities. Example: (pid1, x1) <- pipeFrom "ls" ["/etc"] (pid2, x2) <- pipeBoth "grep" ["x"] x1 putStr x2 ... the grep output is displayed ... forceSuccess pid2 forceSuccess pid1 Remember, when you use the functions that return a String, you must not call forceSuccess until after all data from the String has been consumed. Failure to wait will cause your program to appear to hang. Here is an example of the wrong way to do it: (pid, x) <- pipeFrom "ls" ["/etc"] forceSuccess pid -- Hangs; the called program hasn't terminated yet processTheData x You must instead process the data before calling forceSuccess. When using the hPipe family of functions, this is probably more obvious. Most of this module will be incompatible with Windows. | ||||||||||||||||||||
Synopsis | ||||||||||||||||||||
High-Level Tools | ||||||||||||||||||||
| ||||||||||||||||||||
| ||||||||||||||||||||
| ||||||||||||||||||||
Invokes the specified command in a subprocess, waiting for the result. If the command terminated successfully, return normally. Otherwise, raises a userError with the problem. Implemented in terms of posixRawSystem where supported, and System.Posix.rawSystem otherwise. | ||||||||||||||||||||
| ||||||||||||||||||||
Uses getProcessStatus to obtain the exit status of the given process ID. If the process terminated normally, does nothing. Otherwise, raises an exception with an appropriate error message. This call will block waiting for the given pid to terminate. Not available on Windows. | ||||||||||||||||||||
| ||||||||||||||||||||
Invokes the specified command in a subprocess, waiting for the result. Return the result status. Never raises an exception. Only available on POSIX platforms. Like system(3), this command ignores SIGINT and SIGQUIT and blocks SIGCHLD during its execution. Logs as System.Cmd.Utils.posixRawSystem | ||||||||||||||||||||
| ||||||||||||||||||||
Invokes the specified command in a subprocess, without waiting for the result. Returns the PID of the subprocess -- it is YOUR responsibility to use getProcessStatus or getAnyProcessStatus on that at some point. Failure to do so will lead to resource leakage (zombie processes). This function does nothing with signals. That too is up to you. Logs as System.Cmd.Utils.forkRawSystem | ||||||||||||||||||||
Piping with lazy strings | ||||||||||||||||||||
| ||||||||||||||||||||
Read data from a pipe. Returns a lazy string and a PipeHandle. ONLY AFTER the string has been read completely, You must call either getProcessStatus or forceSuccess on the PipeHandle. Zombies will result otherwise. Not available on Windows. | ||||||||||||||||||||
| ||||||||||||||||||||
Like pipeFrom, but returns data in lines instead of just a String. Shortcut for calling lines on the result from pipeFrom. Note: this function logs as pipeFrom. Not available on Windows. | ||||||||||||||||||||
| ||||||||||||||||||||
Write data to a pipe. Returns a ProcessID. You must call either getProcessStatus or forceSuccess on the ProcessID. Zombies will result otherwise. Not available on Windows. | ||||||||||||||||||||
| ||||||||||||||||||||
Like a combination of pipeTo and pipeFrom; forks an IO thread to send data to the piped program, and simultaneously returns its output stream. The same note about checking the return status applies here as with pipeFrom. Not available on Windows. | ||||||||||||||||||||
Piping with handles | ||||||||||||||||||||
| ||||||||||||||||||||
Read data from a pipe. Returns a Handle and a PipeHandle. When done, you must hClose the handle, and then use either forceSuccess or getProcessStatus on the PipeHandle. Zomeibes will result otherwise. This function logs as pipeFrom. Not available on Windows or with Hugs. | ||||||||||||||||||||
| ||||||||||||||||||||
Write data to a pipe. Returns a PipeHandle and a new Handle to write to. When done, you must hClose the handle, and then use either forceSuccess or getProcessStatus on the PipeHandle. Zomeibes will result otherwise. This function logs as pipeTo. Not available on Windows. | ||||||||||||||||||||
| ||||||||||||||||||||
Like a combination of hPipeTo and hPipeFrom; returns a 3-tuple of (PipeHandle, Data From Pipe, Data To Pipe). When done, you must hClose both handles, and then use either forceSuccess or getProcessStatus on the PipeHandle. Zomeibes will result otherwise. Hint: you will usually need to ForkIO a thread to handle one of the Handles; otherwise, deadlock can result. This function logs as pipeBoth. Not available on Windows. | ||||||||||||||||||||
Low-Level Tools | ||||||||||||||||||||
| ||||||||||||||||||||
| ||||||||||||||||||||
| ||||||||||||||||||||
Open a pipe to the specified command. Passes the handle on to the specified function. The PipeMode specifies what you will be doing. That is, specifing ReadFromPipe sets up a pipe from stdin, and WriteToPipe sets up a pipe from stdout. Not available on Windows. | ||||||||||||||||||||
| ||||||||||||||||||||
| ||||||||||||||||||||
| ||||||||||||||||||||
| ||||||||||||||||||||
Produced by Haddock version 2.6.0 |