rio-0.0.2.0: A standard library for Haskell

Safe HaskellNone
LanguageHaskell2010

RIO.Process

Description

Reading from external processes.

Synopsis

Documentation

withProcess :: MonadUnliftIO m => ProcessConfig stdin stdout stderr -> (Process stdin stdout stderr -> m a) -> m a Source #

Same as withProcess, but generalized to MonadUnliftIO.

withProcess_ :: MonadUnliftIO m => ProcessConfig stdin stdout stderr -> (Process stdin stdout stderr -> m a) -> m a Source #

Same as withProcess_, but generalized to MonadUnliftIO.

data EnvOverride Source #

Override the environment received by a child process.

Constructors

EnvOverride 

Fields

unEnvOverride :: EnvOverride -> Map Text Text Source #

Get the environment variables from an EnvOverride.

modifyEnvOverride :: MonadIO m => EnvOverride -> (Map Text Text -> Map Text Text) -> m EnvOverride Source #

Modify the environment variables of an EnvOverride.

envHelper :: EnvOverride -> [(String, String)] Source #

Helper conversion function.

doesExecutableExist Source #

Arguments

:: MonadIO m 
=> EnvOverride

How to override environment

-> String

Name of executable

-> m Bool 

Check if the given executable exists on the given PATH.

findExecutable Source #

Arguments

:: (MonadIO m, MonadThrow n) 
=> EnvOverride

How to override environment

-> String

Name of executable

-> m (n FilePath)

Full path to that executable on success

Find the complete path for the executable.

Throws a ReadProcessException if unsuccessful.

getEnvOverride :: MonadIO m => m EnvOverride Source #

Load up an EnvOverride from the standard environment.

envSearchPath :: EnvOverride -> [FilePath] Source #

Get the list of directories searched (PATH).

preProcess Source #

Arguments

:: HasEnvOverride env 
=> String

Command name

-> RIO env FilePath 

Perform pre-call-process tasks. Ensure the working directory exists and find the executable path.

Throws a ReadProcessException if unsuccessful.

readProcessNull Source #

Arguments

:: HasEnvOverride env 
=> String

Command

-> [String]

Command line arguments

-> RIO env () 

Read from the process, ignoring any output.

Throws a ReadProcessException exception if the process fails.

augmentPath :: MonadThrow m => [FilePath] -> Maybe Text -> m Text Source #

Augment the PATH environment variable with the given extra paths.

augmentPathMap :: MonadThrow m => [FilePath] -> Map Text Text -> m (Map Text Text) Source #

Apply augmentPath on the PATH value in the given Map.

resetExeCache :: MonadIO m => EnvOverride -> m () Source #

Reset the executable cache.

class HasLogFunc env => HasEnvOverride env where Source #

Minimal complete definition

envOverrideL

withProc Source #

Arguments

:: HasEnvOverride env 
=> FilePath

command to run

-> [String]

command line arguments

-> (ProcessConfig () () () -> RIO env a) 
-> RIO env a 

Provide a ProcessConfig based on the EnvOverride in scope. Deals with resolving the full path, setting the child process's environment variables, setting the working directory, and wrapping the call with withProcessTimeLog for debugging output.

withEnvOverride :: HasEnvOverride env => EnvOverride -> RIO env a -> RIO env a Source #

Set a new EnvOverride in the child reader. Note that this will keep the working directory set in the parent with withWorkingDir.

withModifyEnvOverride :: HasEnvOverride env => (Map Text Text -> Map Text Text) -> RIO env a -> RIO env a Source #

Apply the given function to the modified environment variables. For more details, see withEnvOverride.

withWorkingDir :: HasEnvOverride env => FilePath -> RIO env a -> RIO env a Source #

Set the working directory to be used by child processes.

runEnvNoLogging :: RIO EnvNoLogging a -> IO a Source #

withProcessTimeLog :: (MonadIO m, MonadReader env m, HasLogFunc env, HasCallStack) => Maybe FilePath -> String -> [String] -> m a -> m a Source #

Log running a process with its arguments, for debugging (-v).

This logs one message before running the process and one message after.

showProcessArgDebug :: String -> Text Source #

Show a process arg including speechmarks when necessary. Just for debugging purposes, not functionally important.

exec :: HasEnvOverride env => String -> [String] -> RIO env b Source #

Execute a process within the Stack configured environment.

Execution will not return, because either:

1) On non-windows, execution is taken over by execv of the sub-process. This allows signals to be propagated (#527)

2) On windows, an ExitCode exception will be thrown.

execSpawn :: HasEnvOverride env => String -> [String] -> RIO env a Source #

Like exec, but does not use execv on non-windows. This way, there is a sub-process, which is helpful in some cases (#1306)

This function only exits by throwing ExitCode.