diff options
Diffstat (limited to 'Coolbal/Process.hs')
-rw-r--r-- | Coolbal/Process.hs | 25 |
1 files changed, 25 insertions, 0 deletions
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) |