From b0a22684e0cc7b2421321b30f05e285acc00e470 Mon Sep 17 00:00:00 2001 From: XT Date: Sun, 21 Jul 2024 13:00:09 +0900 Subject: [PATCH] Add: `setCwd`, `setEnv`, `setCloseFds` --- src/RawFilePath/Process.hs | 3 +++ src/RawFilePath/Process/Common.hs | 36 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/RawFilePath/Process.hs b/src/RawFilePath/Process.hs index ef23d74..cbb3bc1 100644 --- a/src/RawFilePath/Process.hs +++ b/src/RawFilePath/Process.hs @@ -126,6 +126,9 @@ module RawFilePath.Process ( -- $configuring ProcessConf, proc, + setCwd, + setEnv, + setCloseFds, -- *** Configuring process standard streams StreamType, diff --git a/src/RawFilePath/Process/Common.hs b/src/RawFilePath/Process/Common.hs index 60a08a3..e947fd3 100644 --- a/src/RawFilePath/Process/Common.hs +++ b/src/RawFilePath/Process/Common.hs @@ -15,6 +15,9 @@ module RawFilePath.Process.Common ( setStdin, setStdout, setStderr, + setCwd, + setEnv, + setCloseFds, UnknownStream, untypeProcess, untypeProcessStdin, @@ -143,6 +146,39 @@ setStderr p newStderr = p{cfgStderr = newStderr} infixl 4 `setStderr` +-- | Set the path to the working directory for the new process. 'Nothing' can be used to unset the property. +-- +-- @since 1.1.2 +setCwd + :: ProcessConf stdin stdout stderr + -> Maybe RawFilePath + -> ProcessConf stdin stdout stderr +setCwd p newCwd = p{cwd = newCwd} + +infixl 4 `setCwd` + +-- | Set the optional environment (otherwise inherit from the current process) +-- +-- @since 1.1.2 +setEnv + :: ProcessConf stdin stdout stderr + -> Maybe [(ByteString, ByteString)] + -> ProcessConf stdin stdout stderr +setEnv p newEnv = p{env = newEnv} + +infixl 4 `setEnv` + +-- | Control whether to close all file descriptors except stdin, stdout and stderr in the new process. +-- +-- @since 1.1.2 +setCloseFds + :: ProcessConf stdin stdout stderr + -> Bool + -> ProcessConf stdin stdout stderr +setCloseFds p newCloseFds = p{closeFds = newCloseFds} + +infixl 4 `setCloseFds` + -- | The process type. The three type variables denote how its standard -- streams were initialized. data Process stdin stdout stderr = Process