From f57e800a1d1a8e9f2bed34428f7f58a375f178fb Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sun, 11 Jul 2021 17:56:34 +0200 Subject: WIP splitting of Target module and towards parallel builds --- Coolbal/Process.hs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Coolbal/Process.hs (limited to 'Coolbal/Process.hs') diff --git a/Coolbal/Process.hs b/Coolbal/Process.hs new file mode 100644 index 0000000..8b4576c --- /dev/null +++ b/Coolbal/Process.hs @@ -0,0 +1,25 @@ +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) -- cgit v1.2.3-70-g09d2