module Distribution.Compat.Process (
createProcess,
runInteractiveProcess,
rawSystem,
enableProcessJobs,
) where
import System.Exit (ExitCode (..))
import System.IO (Handle)
import System.Process (CreateProcess, ProcessHandle)
import qualified System.Process as Process
#if MIN_VERSION_process(1,2,0)
import System.Process (waitForProcess)
#endif
enableProcessJobs :: CreateProcess -> CreateProcess
#ifdef MIN_VERSION_process
#if MIN_VERSION_process(1,6,9)
enableProcessJobs cp = cp {Process.use_process_jobs = True}
#else
enableProcessJobs cp = cp
#endif
#else
enableProcessJobs cp = cp
#endif
createProcess :: CreateProcess
-> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
createProcess = Process.createProcess . enableProcessJobs
rawSystem :: String -> [String] -> IO ExitCode
rawSystem cmd args = do
#if MIN_VERSION_process(1,2,0)
(_,_,_,p) <- createProcess (Process.proc cmd args) { Process.delegate_ctlc = True }
waitForProcess p
#else
Process.rawSystem cmd args
#endif
runInteractiveProcess
:: FilePath
-> [String]
-> Maybe FilePath
-> Maybe [(String,String)]
-> IO (Handle,Handle,Handle,ProcessHandle)
runInteractiveProcess cmd args mb_cwd mb_env = do
(mb_in, mb_out, mb_err, p) <-
createProcess (Process.proc cmd args)
{ Process.std_in = Process.CreatePipe,
Process.std_out = Process.CreatePipe,
Process.std_err = Process.CreatePipe,
Process.env = mb_env,
Process.cwd = mb_cwd }
return (fromJust mb_in, fromJust mb_out, fromJust mb_err, p)
where
fromJust = maybe (error "runInteractiveProcess: fromJust") id