Safe Haskell | None |
---|
Generalized versions of the functions
readProcess
, and
readProcessWithExitCode
.
- class ListLikeIO a c => ListLikePlus a c where
- readProcessInterleaved :: (ListLikePlus a c, Monoid b) => (ProcessHandle -> b) -> (ExitCode -> b) -> (a -> b) -> (a -> b) -> CreateProcess -> a -> IO b
- readInterleaved :: forall a b c. (ListLikePlus a c, Monoid b) => b -> [(a -> b, Handle)] -> IO b -> IO b
- readCreateProcessWithExitCode :: forall a c. ListLikePlus a c => CreateProcess -> a -> IO (ExitCode, a, a)
- readCreateProcess :: ListLikePlus a c => CreateProcess -> a -> IO a
- readProcessWithExitCode :: ListLikePlus a c => FilePath -> [String] -> a -> IO (ExitCode, a, a)
- readProcess :: ListLikePlus a c => FilePath -> [String] -> a -> IO a
- showCmdSpecForUser :: CmdSpec -> String
Documentation
class ListLikeIO a c => ListLikePlus a c whereSource
Class of types which can be used as the input and outputs of these process functions.
setModes :: a -> (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) -> IO ()Source
Perform initialization on the handles returned by createProcess based on this ListLikePlus instance - typically setting binary mode on all the file descriptors if the element type is Word8. If this is not done, reading something other than text (such as a .jpg or .pdf file) will usually fail with a decoding error.
readChunks :: Handle -> IO [a]Source
Read the list of chunks from this handle. For lazy types this is just a call to hGetContents followed by toChunks. For strict types it might return a singleton list. Strings are trickier.
ListLikePlus String Char | This String instance is implemented using the Lazy Text instance.
Otherwise (without some serious coding) String would be a strict
instance . Note that the |
ListLikePlus ByteString Word8 | |
ListLikePlus ByteString Word8 | |
ListLikePlus Text Char | |
ListLikePlus Text Char |
readProcessInterleaved :: (ListLikePlus a c, Monoid b) => (ProcessHandle -> b) -> (ExitCode -> b) -> (a -> b) -> (a -> b) -> CreateProcess -> a -> IO bSource
Read the output of a process and use the argument functions to convert it into a Monoid, preserving the order of appearance of the different chunks of output from standard output and standard error.
readInterleaved :: forall a b c. (ListLikePlus a c, Monoid b) => b -> [(a -> b, Handle)] -> IO b -> IO bSource
Simultaneously read the output from several file handles, using the associated functions to add them to a Monoid b in the order they appear. This closes each handle on EOF, because AFAIK it is the only useful thing to do with a file handle that has reached EOF.
readCreateProcessWithExitCodeSource
:: forall a c . ListLikePlus a c | |
=> CreateProcess | process to run |
-> a | standard input |
-> IO (ExitCode, a, a) | exitcode, stdout, stderr, exception |
An implementation of readProcessWithExitCode
with a two generalizations: (1) The input and outputs can be any
instance of ListLikePlus
, and (2) The CreateProcess is passes an
argument, so you can use either proc
or
rawSystem
and you can modify its fields such as
cwd
before the process starts
:: ListLikePlus a c | |
=> CreateProcess | process to run |
-> a | standard input |
-> IO a | stdout |
An implementation of readProcess
with a two
generalizations: (1) The input and outputs can be any instance of
ListLikePlus
, and (2) The CreateProcess is passes an argument, so
you can use either proc
or
rawSystem
and you can modify its fields such as
cwd
before the process starts
This can't be implemented by calling readProcessInterleaved because
the std_err field needs to be set to Inherit, which means that
createProcess
returns no stderr handle. Instead, we have a
nearly identical copy of the readProcessInterleaved
code which
only passes one pair readInterleaved
. REMEMBER to keep these two
in sync if there are future changes!
:: ListLikePlus a c | |
=> FilePath | command to run |
-> [String] | any arguments |
-> a | standard input |
-> IO (ExitCode, a, a) | exitcode, stdout, stderr |
A version of readProcessWithExitCode
that uses
any instance of ListLikePlus
instead of String
, implemented
using readCreateProcessWithExitCode
.
:: ListLikePlus a c | |
=> FilePath | command to run |
-> [String] | any arguments |
-> a | standard input |
-> IO a | stdout |
Implementation of readProcess
that uses any
instance of ListLikePlus
instead of String
, implemented using
readCreateProcess
.