diff options
author | Joey Hess <joey@kitenet.net> | 2010-10-19 01:45:45 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2010-10-19 01:45:45 -0400 |
commit | 7afac113443b8e93e19ad87d769a24c52706f551 (patch) | |
tree | 74afed5559f0c6ee8d6c38a8c9d6e5919cb4f0b2 /Utility.hs | |
parent | c7664588f81fe27b3e88d49523ef3c483ac6481a (diff) |
add boolSystem
Diffstat (limited to 'Utility.hs')
-rw-r--r-- | Utility.hs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/Utility.hs b/Utility.hs index e4278ff3f..09b973002 100644 --- a/Utility.hs +++ b/Utility.hs @@ -6,10 +6,15 @@ module Utility ( hGetContentsStrict, parentDir, relPathCwdToDir, - relPathDirToDir + relPathDirToDir, + boolSystem ) where import System.IO +import System.Cmd +import System.Exit +import System.Posix.Signals +import Data.Typeable import System.Posix.IO import Data.String.Utils import System.Path @@ -88,3 +93,18 @@ relPathDirToDir from to = dotdots = take ((length pfrom) - numcommon) $ repeat ".." numcommon = length $ common path = join s $ dotdots ++ uncommon + +{- Run a system command, and returns True or False + - if it succeeded or failed. + - + - An error is thrown if the command exits due to SIGINT, + - to propigate ctrl-c. + -} +boolSystem :: FilePath -> [String] -> IO Bool +boolSystem command params = do + r <- rawSystem command params + case r of + ExitSuccess -> return True + ExitFailure e -> if Just e == cast sigINT + then error $ command ++ "interrupted" + else return False |