module Lambdabot.Util.Process
( run
) where
import System.Process
run :: FilePath -> String -> (String -> String) -> IO String
run :: FilePath -> FilePath -> (FilePath -> FilePath) -> IO FilePath
run binary :: FilePath
binary src :: FilePath
src scrub :: FilePath -> FilePath
scrub = do
(_,out :: FilePath
out,err :: FilePath
err) <- FilePath
-> [FilePath] -> FilePath -> IO (ExitCode, FilePath, FilePath)
readProcessWithExitCode FilePath
binary [] FilePath
src
let o :: FilePath
o = FilePath -> FilePath
scrub FilePath
out
e :: FilePath
e = FilePath -> FilePath
scrub FilePath
err
FilePath -> IO FilePath
forall (m :: * -> *) a. Monad m => a -> m a
return (FilePath -> IO FilePath) -> FilePath -> IO FilePath
forall a b. (a -> b) -> a -> b
$ case () of {_
| FilePath -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null FilePath
o Bool -> Bool -> Bool
&& FilePath -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null FilePath
e -> "Done."
| FilePath -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null FilePath
o -> FilePath
e
| Bool
otherwise -> FilePath
o
}