-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A replacement for System.Exit and System.Process -- -- Specifically, this library replaces System.Exit.ExitCode with -- an abstract data type. @package Command @version 0.0.1 module System.Command -- | This is the most general way to spawn an external process. The process -- can be a command line to be executed by a shell or a raw command with -- a list of arguments. The stdin, stdout, and stderr streams of the new -- process may individually be attached to new pipes, to existing -- Handles, or just inherited from the parent (the default.) -- -- The details of how to create the process are passed in the -- CreateProcess record. To make it easier to construct a -- CreateProcess, the functions proc and shell are -- supplied that fill in the fields with default values which can be -- overriden as needed. -- -- createProcess returns (mb_stdin_hdl, mb_stdout_hdl, -- mb_stderr_hdl, p), where -- --
-- r <- createProcess (proc "ls" []) ---- -- To create a pipe from which to read the output of ls: -- --
-- (_, Just hout, _, _) <-
-- createProcess (proc "ls" []){ std_out = CreatePipe }
--
--
-- To also set the directory in which to run ls:
--
--
-- (_, Just hout, _, _) <-
-- createProcess (proc "ls" []){ cwd = Just "\home\bob",
-- std_out = CreatePipe }
--
createProcess :: CreateProcess -> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
-- | Construct a CreateProcess record for passing to
-- createProcess, representing a command to be passed to the
-- shell.
shell :: String -> CreateProcess
-- | Construct a CreateProcess record for passing to
-- createProcess, representing a raw command with arguments.
proc :: FilePath -> [String] -> CreateProcess
data CreateProcess :: *
CreateProcess :: CmdSpec -> Maybe FilePath -> Maybe [(String, String)] -> StdStream -> StdStream -> StdStream -> Bool -> CreateProcess
-- | Executable & arguments, or shell command
cmdspec :: CreateProcess -> CmdSpec
-- | Optional path to the working directory for the new process
cwd :: CreateProcess -> Maybe FilePath
-- | Optional environment (otherwise inherit from the current process)
env :: CreateProcess -> Maybe [(String, String)]
-- | How to determine stdin
std_in :: CreateProcess -> StdStream
-- | How to determine stdout
std_out :: CreateProcess -> StdStream
-- | How to determine stderr
std_err :: CreateProcess -> StdStream
-- | Close all file descriptors except stdin, stdout and stderr in the new
-- process (on Windows, only works if std_in, std_out, and std_err are
-- all Inherit)
close_fds :: CreateProcess -> Bool
data CmdSpec :: *
-- | a command line to execute using the shell
ShellCommand :: String -> CmdSpec
-- | the filename of an executable with a list of arguments
RawCommand :: FilePath -> [String] -> CmdSpec
data StdStream :: *
-- | Inherit Handle from parent
Inherit :: StdStream
-- | Use the supplied Handle
UseHandle :: Handle -> StdStream
-- | Create a new pipe. The returned Handle will use the default
-- encoding and newline translation mode (just like Handles
-- created by openFile).
CreatePipe :: StdStream
data ProcessHandle :: *
-- | 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.
--
-- 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.
readProcessWithExitCode :: FilePath -> [String] -> String -> IO (ExitCode, String, String)
-- | Runs a command using the shell.
runCommand :: String -> 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.
runProcess :: FilePath -> [String] -> Maybe FilePath -> Maybe [(String, String)] -> Maybe Handle -> Maybe Handle -> Maybe Handle -> IO ProcessHandle
-- | Runs a command using the shell, and returns Handles that may be
-- used to communicate with the process via its stdin,
-- stdout, and stderr respectively. The Handles
-- are initially in binary mode; if you need them to be in text mode then
-- use hSetBinaryMode.
runInteractiveCommand :: String -> 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. runInteractiveProcess :: FilePath -> [String] -> Maybe FilePath -> Maybe [(String, String)] -> IO (Handle, Handle, Handle, ProcessHandle) -- | readProcess forks an external process, reads its standard output -- strictly, blocking until the process terminates, and returns the -- output string. -- -- Output is returned strictly, so this is not suitable for interactive -- applications. -- -- 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: -- --