Unixutils-1.17: A crude interface between Haskell and Unix-like operating systems

System.Unix.Process

Contents

Description

functions for killing processes, running processes, etc

Synopsis

Strict process running

simpleProcess :: FilePath -> [String] -> IO (String, String, ExitCode)Source

simpleProcess - run a process returning (stdout, stderr, exitcode)

Warning - stdout and stderr will be read strictly so that we do not deadlock when trying to check the exitcode. Do not try doing something like, simpleProcess ["yes"]

NOTE: this may still dead-lock because we first strictly read outStr and then errStr. Perhaps we should use forkIO or something?

Lazy process running

type Process = (Handle, Handle, Handle, ProcessHandle)Source

This is the type returned by runInteractiveProcess et. al.

data Output Source

The process returns a list of objects of type Output. There will be one Result object at the end of the list (if the list has an end.)

Instances

lazyRun :: ByteString -> Process -> IO [Output]Source

Take the tuple like that returned by runInteractiveProcess, create a process, send the list of inputs to its stdin and return the lazy list of Output objects.

lazyCommand :: String -> ByteString -> IO [Output]Source

Current verbosity level.

Create a process with runInteractiveCommand and run it with lazyRun.

lazyProcess :: FilePath -> [String] -> Maybe FilePath -> Maybe [(String, String)] -> ByteString -> IO [Output]Source

Create a process with runInteractiveProcess and run it with lazyRun.

stdoutOnly :: [Output] -> ByteStringSource

Filter everything except stdout from the output list.

stderrOnly :: [Output] -> ByteStringSource

Filter everything except stderr from the output list.

outputOnly :: [Output] -> ByteStringSource

Filter the exit codes output list and merge the two output streams in the order they appear.

checkResult :: (Int -> a) -> a -> [Output] -> aSource

mergeToStderr :: [Output] -> [Output]Source

Turn all the Stdout text into Stderr, preserving the order.

mergeToStdout :: [Output] -> [Output]Source

Turn all the Stderr text into Stdout, preserving the order.

collectStdout :: [Output] -> (ByteString, [Output])Source

Split out and concatenate Stdout

collectStderr :: [Output] -> (ByteString, [Output])Source

Split out and concatenate Stderr

collectOutput :: [Output] -> (ByteString, ByteString, [ExitCode])Source

Split out and concatenate both Stdout and Stderr, leaving only the exit code.

collectOutputUnpacked :: [Output] -> (String, String, [ExitCode])Source

Collect all output, unpack and concatenate.

data ExitCode

Constructors

ExitSuccess

indicates successful termination;

ExitFailure Int

indicates program failure with an exit code. The exact interpretation of the code is operating-system dependent. In particular, some values may be prohibited (e.g. 0 on a POSIX-compliant system).

exitCodeOnly :: [Output] -> [ExitCode]Source

Filter everything except the exit code from the output list.

hPutNonBlocking :: Handle -> ByteString -> IO Int64Source

This belongs in Data.ByteString. See ticket 1070, http://hackage.haskell.org/trac/ghc/ticket/1070.

Process killing

killByCwd :: FilePath -> IO [(String, Maybe String)]Source

Kill the processes whose working directory is in or under the given directory.