more general readProcess' merged from propellor

This commit is contained in:
Joey Hess 2014-11-19 00:55:33 -04:00
parent 08f2c2cb0b
commit 0da402e0b9

View file

@ -13,6 +13,7 @@ module Utility.Process (
CreateProcess(..), CreateProcess(..),
StdHandle(..), StdHandle(..),
readProcess, readProcess,
readProcess',
readProcessEnv, readProcessEnv,
writeReadProcessEnv, writeReadProcessEnv,
forceSuccessProcess, forceSuccessProcess,
@ -66,17 +67,19 @@ readProcess :: FilePath -> [String] -> IO String
readProcess cmd args = readProcessEnv cmd args Nothing readProcess cmd args = readProcessEnv cmd args Nothing
readProcessEnv :: FilePath -> [String] -> Maybe [(String, String)] -> IO String readProcessEnv :: FilePath -> [String] -> Maybe [(String, String)] -> IO String
readProcessEnv cmd args environ = readProcessEnv cmd args environ = readProcess' p
withHandle StdoutHandle createProcessSuccess p $ \h -> do
output <- hGetContentsStrict h
hClose h
return output
where where
p = (proc cmd args) p = (proc cmd args)
{ std_out = CreatePipe { std_out = CreatePipe
, env = environ , env = environ
} }
readProcess' :: CreateProcess -> IO String
readProcess' p = withHandle StdoutHandle createProcessSuccess p $ \h -> do
output <- hGetContentsStrict h
hClose h
return output
{- Runs an action to write to a process on its stdin, {- Runs an action to write to a process on its stdin,
- returns its output, and also allows specifying the environment. - returns its output, and also allows specifying the environment.
-} -}