Safe Haskell | None |
---|---|
Language | Haskell2010 |
Reading from external processes.
- readProcessStdout :: (MonadIO m, MonadLogger m, MonadBaseControl IO m, MonadCatch m) => Maybe (Path Abs Dir) -> EnvOverride -> String -> [String] -> m ByteString
- tryProcessStdout :: (MonadIO m, MonadLogger m, MonadBaseControl IO m, MonadCatch m) => Maybe (Path Abs Dir) -> EnvOverride -> String -> [String] -> m (Either ReadProcessException ByteString)
- sinkProcessStdout :: (MonadIO m, MonadLogger m, MonadBaseControl IO m, MonadCatch m) => Maybe (Path Abs Dir) -> EnvOverride -> String -> [String] -> Sink ByteString IO a -> m a
- readProcess :: FilePath -> [String] -> String -> IO String
- data EnvOverride = EnvOverride {
- eoTextMap :: Map Text Text
- eoStringList :: [(String, String)]
- eoPath :: [FilePath]
- eoExeCache :: IORef (Map FilePath (Either ReadProcessException (Path Abs File)))
- eoExeExtension :: String
- unEnvOverride :: EnvOverride -> Map Text Text
- mkEnvOverride :: MonadIO m => Platform -> Map Text Text -> m EnvOverride
- envHelper :: EnvOverride -> Maybe [(String, String)]
- doesExecutableExist :: MonadIO m => EnvOverride -> String -> m Bool
- findExecutable :: (MonadIO m, MonadThrow n) => EnvOverride -> String -> m (n (Path Abs File))
- getEnvOverride :: MonadIO m => Platform -> m EnvOverride
- envSearchPath :: EnvOverride -> [FilePath]
- preProcess :: MonadIO m => Maybe (Path Abs Dir) -> EnvOverride -> String -> m FilePath
- readProcessNull :: (MonadIO m, MonadLogger m, MonadBaseControl IO m, MonadCatch m) => Maybe (Path Abs Dir) -> EnvOverride -> String -> [String] -> m ()
- readInNull :: (MonadIO m, MonadLogger m, MonadBaseControl IO m, MonadCatch m) => Path Abs Dir -> FilePath -> EnvOverride -> [String] -> Maybe Text -> m ()
- logProcessRun :: Q Exp
- data ReadProcessException
- augmentPath :: [FilePath] -> Maybe Text -> Text
- augmentPathMap :: [FilePath] -> Map Text Text -> Map Text Text
Documentation
readProcessStdout :: (MonadIO m, MonadLogger m, MonadBaseControl IO m, MonadCatch m) => Maybe (Path Abs Dir) -> EnvOverride -> String -> [String] -> m ByteString Source
Produce a strict ByteString
from the stdout of a
process. Throws a ProcessExitedUnsuccessfully
exception if the
process fails.
tryProcessStdout :: (MonadIO m, MonadLogger m, MonadBaseControl IO m, MonadCatch m) => Maybe (Path Abs Dir) -> EnvOverride -> String -> [String] -> m (Either ReadProcessException ByteString) Source
Try to produce a strict ByteString
from the stdout of a
process.
:: (MonadIO m, MonadLogger m, MonadBaseControl IO m, MonadCatch m) | |
=> Maybe (Path Abs Dir) | |
-> EnvOverride | |
-> String | |
-> [String] | |
-> Sink ByteString IO a | Sink for stdout |
-> m a |
Consume the stdout of a process feeding strict ByteString
s to a consumer.
If the process fails, spits out stdout and stderr as error log
level. Should not be used for long-running processes or ones with
lots of output; for that use sinkProcessStdoutLogStderr
.
:: FilePath | Filename of the executable (see |
-> [String] | any arguments |
-> String | standard input |
-> IO String | stdout |
readProcess
forks an external process, reads its standard output
strictly, blocking until the process terminates, and returns the output
string. The external process inherits the standard error.
If an asynchronous exception is thrown to the thread executing
readProcess
, the forked process will be terminated and readProcess
will
wait (block) until the process has been terminated.
Output is returned strictly, so this is not suitable for interactive applications.
This function throws an IOError
if the process ExitCode
is
anything other than ExitSuccess
. If instead you want to get the
ExitCode
then use readProcessWithExitCode
.
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:
- The command to run, which must be in the $PATH, or an absolute or relative path
- A list of separate command line arguments to the program
- A string to pass on standard input to the forked process.
data EnvOverride Source
Override the environment received by a child process
EnvOverride | |
|
unEnvOverride :: EnvOverride -> Map Text Text Source
Get the environment variables from EnvOverride
mkEnvOverride :: MonadIO m => Platform -> Map Text Text -> m EnvOverride Source
Create a new EnvOverride
doesExecutableExist :: MonadIO m => EnvOverride -> String -> m Bool Source
Check if the given executable exists on the given PATH
findExecutable :: (MonadIO m, MonadThrow n) => EnvOverride -> String -> m (n (Path Abs File)) Source
Find the complete path for the executable
getEnvOverride :: MonadIO m => Platform -> m EnvOverride Source
Load up an EnvOverride from the standard environment
envSearchPath :: EnvOverride -> [FilePath] Source
Get the list of directories searched
preProcess :: MonadIO m => Maybe (Path Abs Dir) -> EnvOverride -> String -> m FilePath Source
Perform pre-call-process tasks. Ensure the working directory exists and find the executable path.
readProcessNull :: (MonadIO m, MonadLogger m, MonadBaseControl IO m, MonadCatch m) => Maybe (Path Abs Dir) -> EnvOverride -> String -> [String] -> m () Source
Read from the process, ignoring any output.
:: (MonadIO m, MonadLogger m, MonadBaseControl IO m, MonadCatch m) | |
=> Path Abs Dir | directory to run in |
-> FilePath | command to run |
-> EnvOverride | |
-> [String] | command line arguments |
-> Maybe Text | |
-> m () |
Run the given command in the given directory. If it exits with anything
but success, prints an error and then calls exitWith
to exit the program.
logProcessRun :: Q Exp Source
Log running a process with its arguments, for debugging (-v).
augmentPath :: [FilePath] -> Maybe Text -> Text Source
Augment the PATH environment variable with the given extra paths
augmentPathMap :: [FilePath] -> Map Text Text -> Map Text Text Source
Apply augmentPath
on the PATH value in the given Map.