summaryrefslogtreecommitdiff
path: root/Coolbal/Process.hs
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2021-07-11 17:56:34 +0200
committerTom Smeding <tom@tomsmeding.com>2021-07-11 17:56:34 +0200
commitf57e800a1d1a8e9f2bed34428f7f58a375f178fb (patch)
tree7164b0a9bcf03703a6a7f44f5fa04e5847d876e5 /Coolbal/Process.hs
parent317f1e27688a082926f39ec897f5a38d01a07ce7 (diff)
WIP splitting of Target module and towards parallel buildsHEADmaster
Diffstat (limited to 'Coolbal/Process.hs')
-rw-r--r--Coolbal/Process.hs25
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)