Portability | portable |
---|---|
Stability | provisional |
Maintainer | John Goerzen <jgoerzen@complete.org> |
Copyright (c) 2006-2007 John Goerzen, jgoerzen@complete.org
- class Show a => ShellCommand a where
- data (ShellCommand a, ShellCommand b) => PipeCommand a b = PipeCommand a b
- (-|-) :: (ShellCommand a, ShellCommand b) => a -> b -> PipeCommand a b
- class RunResult a where
- run :: ShellCommand b => b -> a
- runIO :: ShellCommand a => a -> IO ()
- runSL :: ShellCommand a => a -> IO String
- type InvokeResult = (String, IO ProcessStatus)
- tryEC :: IO a -> IO (Either ProcessStatus a)
- catchEC :: IO a -> (ProcessStatus -> IO a) -> IO a
Documentation
class Show a => ShellCommand a whereSource
A shell command is something we can invoke, pipe to, pipe from, or pipe in both directions. All commands that can be run as shell commands must define these methods.
Minimum implementation is fdInvoke
.
:: a | The command |
-> Fd | fd to pass to it as stdin |
-> Fd | fd to pass to it as stdout |
-> [Fd] | Fds to close in the child. Will not harm Fds this child needs for stdin and stdout. |
-> IO () | Action to run post-fork in child (or in main process if it doesn't fork) |
-> IO [InvokeResult] | Returns an action that, when evaluated, waits for the process to finish and returns an exit code. |
Invoke a command.
ShellCommand String | An instance of |
ShellCommand ([String] -> [String]) | An instance of A [String] is generated from a Handle via the So, this function is intended to operate upon lines of input and produce lines of output. |
ShellCommand ([String] -> IO [String]) | The same for an IO function |
ShellCommand (String -> IO String) | |
ShellCommand (String -> String) | An instance of |
ShellCommand (String, [String]) | An instance of |
(ShellCommand a, ShellCommand b) => ShellCommand (PipeCommand a b) | An instance of |
data (ShellCommand a, ShellCommand b) => PipeCommand a b Source
PipeCommand a b |
(ShellCommand a, ShellCommand b) => Show (PipeCommand a b) | |
(ShellCommand a, ShellCommand b) => ShellCommand (PipeCommand a b) | An instance of |
(-|-) :: (ShellCommand a, ShellCommand b) => a -> b -> PipeCommand a bSource
Pipe the output of the first command into the input of the second.
Different ways to get data from run
.
- IO () runs, throws an exception on error, and sends stdout to stdout
- IO String runs, throws an exception on error, reads stdout into a buffer, and returns it as a string.
- IO [String] is same as IO String, but returns the results as lines
- IO ProcessStatus runs and returns a ProcessStatus with the exit information. stdout is sent to stdout. Exceptions are not thrown.
- IO (String, ProcessStatus) is like IO ProcessStatus, but also includes a description of the last command in the pipe to have an error (or the last command, if there was no error)
- IO Int returns the exit code from a program directly. If a signal caused the command to be reaped, returns 128 + SIGNUM.
- IO Bool returns True if the program exited normally (exit code 0, not stopped by a signal) and False otherwise.
run :: ShellCommand b => b -> aSource
Runs a command (or pipe of commands), with results presented in any number of different ways.
runIO :: ShellCommand a => a -> IO ()Source
runSL :: ShellCommand a => a -> IO StringSource
Another convenience function. This returns the first line of the output, with any trailing newlines or whitespace stripped off. No leading whitespace is stripped. This function will raise an exception if there is not at least one line of output. Mnemonic: runSL means "run single line".
This command exists separately from run
because there is already a
run
instance that returns a String, though that instance returns the
entirety of the output in that String.
type InvokeResult = (String, IO ProcessStatus)Source
Result type for shell commands