module Coolbal.Process where import System.Exit (ExitCode(..)) import System.Process import System.IO (hGetContents) import Coolbal.Log import Coolbal.Options runCommand :: Flags -> String -> [String] -> IO ExitCode runCommand flags cmd args = do logVerbose flags "cmd" $ "Running command: " ++ showCommandForUser cmd args (_, _, _, ph) <- createProcess (proc cmd args) waitForProcess ph readCommand :: Flags -> String -> [String] -> IO (Either ExitCode String) readCommand flags cmd args = do logVerbose flags "cmd" $ "Running command: " ++ showCommandForUser cmd args (_, Just handle, _, ph) <- createProcess (proc cmd args) { std_out = CreatePipe } output <- hGetContents handle code <- waitForProcess ph case code of ExitSuccess -> return (Right output) ExitFailure _ -> return (Left code)