{-# LANGUAGE CPP #-}
module UnliftIO.Process (
CreateProcess(..), CmdSpec(..), StdStream(..), ProcessHandle, createProcess
#if MIN_VERSION_process(1,2,1)
, createProcess_
#endif
, P.shell, P.proc
, callProcess, callCommand, spawnProcess, spawnCommand
#if MIN_VERSION_process(1,2,3)
, readCreateProcess
#endif
, readProcess
#if MIN_VERSION_process(1,2,3)
, readCreateProcessWithExitCode
#endif
, readProcessWithExitCode
#if MIN_VERSION_process(1,4,3)
, withCreateProcess
#endif
, P.showCommandForUser
, waitForProcess, getProcessExitCode, terminateProcess, interruptProcessGroupOf
#if MIN_VERSION_process(1,2,1)
, createPipe
#endif
#if MIN_VERSION_process(1,4,2)
, createPipeFd
#endif
) where
import Control.Monad.IO.Unlift
import System.Exit
import System.IO
import System.Posix.Internals
import System.Process
( CmdSpec(..)
, CreateProcess(..)
, ProcessHandle
, StdStream(..)
)
import qualified System.Process as P
{-# INLINE createProcess #-}
createProcess ::
MonadIO m
=> CreateProcess
-> m (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
createProcess :: forall (m :: * -> *).
MonadIO m =>
CreateProcess
-> m (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
createProcess = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. CreateProcess
-> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
P.createProcess
#if MIN_VERSION_process(1,2,1)
{-# INLINE createProcess_ #-}
createProcess_ ::
MonadIO m
=> String
-> CreateProcess
-> m (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
createProcess_ :: forall (m :: * -> *).
MonadIO m =>
String
-> CreateProcess
-> m (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
createProcess_ String
msg CreateProcess
proc_ = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (String
-> CreateProcess
-> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
P.createProcess_ String
msg CreateProcess
proc_)
#endif
{-# INLINE callProcess #-}
callProcess :: MonadIO m => FilePath -> [String] -> m ()
callProcess :: forall (m :: * -> *). MonadIO m => String -> [String] -> m ()
callProcess String
cmd [String]
args = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (String -> [String] -> IO ()
P.callProcess String
cmd [String]
args)
{-# INLINE callCommand #-}
callCommand :: MonadIO m => String -> m ()
callCommand :: forall (m :: * -> *). MonadIO m => String -> m ()
callCommand = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IO ()
P.callCommand
{-# INLINE spawnProcess #-}
spawnProcess :: MonadIO m => FilePath -> [String] -> m ProcessHandle
spawnProcess :: forall (m :: * -> *).
MonadIO m =>
String -> [String] -> m ProcessHandle
spawnProcess String
cmd [String]
args = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (String -> [String] -> IO ProcessHandle
P.spawnProcess String
cmd [String]
args)
{-# INLINE spawnCommand #-}
spawnCommand :: MonadIO m => String -> m ProcessHandle
spawnCommand :: forall (m :: * -> *). MonadIO m => String -> m ProcessHandle
spawnCommand = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IO ProcessHandle
P.spawnCommand
#if MIN_VERSION_process(1,2,3)
{-# INLINE readCreateProcess #-}
readCreateProcess :: MonadIO m => CreateProcess -> String -> m String
readCreateProcess :: forall (m :: * -> *).
MonadIO m =>
CreateProcess -> String -> m String
readCreateProcess CreateProcess
cp String
input = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (CreateProcess -> String -> IO String
P.readCreateProcess CreateProcess
cp String
input)
#endif
{-# INLINE readProcess #-}
readProcess :: MonadIO m => FilePath -> [String] -> String -> m String
readProcess :: forall (m :: * -> *).
MonadIO m =>
String -> [String] -> String -> m String
readProcess String
cmd [String]
args String
input = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (String -> [String] -> String -> IO String
P.readProcess String
cmd [String]
args String
input)
#if MIN_VERSION_process(1,2,3)
{-# INLINE readCreateProcessWithExitCode #-}
readCreateProcessWithExitCode ::
MonadIO m => CreateProcess -> String -> m (ExitCode, String, String)
readCreateProcessWithExitCode :: forall (m :: * -> *).
MonadIO m =>
CreateProcess -> String -> m (ExitCode, String, String)
readCreateProcessWithExitCode CreateProcess
cp String
input =
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (CreateProcess -> String -> IO (ExitCode, String, String)
P.readCreateProcessWithExitCode CreateProcess
cp String
input)
#endif
{-# INLINE readProcessWithExitCode #-}
readProcessWithExitCode ::
MonadIO m => FilePath -> [String] -> String -> m (ExitCode, String, String)
readProcessWithExitCode :: forall (m :: * -> *).
MonadIO m =>
String -> [String] -> String -> m (ExitCode, String, String)
readProcessWithExitCode String
cmd [String]
args String
input =
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (String -> [String] -> String -> IO (ExitCode, String, String)
P.readProcessWithExitCode String
cmd [String]
args String
input)
#if MIN_VERSION_process(1,4,3)
{-# INLINE withCreateProcess #-}
withCreateProcess ::
MonadUnliftIO m
=> CreateProcess
-> (Maybe Handle -> Maybe Handle -> Maybe Handle -> ProcessHandle -> m a)
-> m a
withCreateProcess :: forall (m :: * -> *) a.
MonadUnliftIO m =>
CreateProcess
-> (Maybe Handle
-> Maybe Handle -> Maybe Handle -> ProcessHandle -> m a)
-> m a
withCreateProcess CreateProcess
c Maybe Handle
-> Maybe Handle -> Maybe Handle -> ProcessHandle -> m a
action =
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO
(\forall a. m a -> IO a
u ->
forall a.
CreateProcess
-> (Maybe Handle
-> Maybe Handle -> Maybe Handle -> ProcessHandle -> IO a)
-> IO a
P.withCreateProcess
CreateProcess
c
(\Maybe Handle
stdin_h Maybe Handle
stdout_h Maybe Handle
stderr_h ProcessHandle
proc_h ->
forall a. m a -> IO a
u (Maybe Handle
-> Maybe Handle -> Maybe Handle -> ProcessHandle -> m a
action Maybe Handle
stdin_h Maybe Handle
stdout_h Maybe Handle
stderr_h ProcessHandle
proc_h)))
#endif
{-# INLINE waitForProcess #-}
waitForProcess :: MonadIO m => ProcessHandle -> m ExitCode
waitForProcess :: forall (m :: * -> *). MonadIO m => ProcessHandle -> m ExitCode
waitForProcess = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProcessHandle -> IO ExitCode
P.waitForProcess
{-# INLINE getProcessExitCode #-}
getProcessExitCode :: MonadIO m => ProcessHandle -> m (Maybe ExitCode)
getProcessExitCode :: forall (m :: * -> *).
MonadIO m =>
ProcessHandle -> m (Maybe ExitCode)
getProcessExitCode = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProcessHandle -> IO (Maybe ExitCode)
P.getProcessExitCode
{-# INLINE terminateProcess #-}
terminateProcess :: MonadIO m => ProcessHandle -> m ()
terminateProcess :: forall (m :: * -> *). MonadIO m => ProcessHandle -> m ()
terminateProcess = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProcessHandle -> IO ()
P.terminateProcess
{-# INLINE interruptProcessGroupOf #-}
interruptProcessGroupOf :: MonadIO m => ProcessHandle -> m ()
interruptProcessGroupOf :: forall (m :: * -> *). MonadIO m => ProcessHandle -> m ()
interruptProcessGroupOf = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProcessHandle -> IO ()
P.interruptProcessGroupOf
#if MIN_VERSION_process(1,2,1)
{-# INLINE createPipe #-}
createPipe :: MonadIO m => m (Handle, Handle)
createPipe :: forall (m :: * -> *). MonadIO m => m (Handle, Handle)
createPipe = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO (Handle, Handle)
P.createPipe
#endif
#if MIN_VERSION_process(1,4,2)
{-# INLINE createPipeFd #-}
createPipeFd :: MonadIO m => m (FD, FD)
createPipeFd :: forall (m :: * -> *). MonadIO m => m (FD, FD)
createPipeFd = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO (FD, FD)
P.createPipeFd
#endif