-- Copyright (c) 2004-6 Don Stewart - http://www.cse.unsw.edu.au/~dons
-- GPL version 2 or later (see http://www.gnu.org/copyleft/gpl.html)

module Lambdabot.Util.Process
    ( run
    ) where

import System.Process

run :: FilePath -> String -> (String -> String) -> IO String
run :: FilePath -> FilePath -> (FilePath -> FilePath) -> IO FilePath
run FilePath
binary FilePath
src FilePath -> FilePath
scrub = do
    (ExitCode
_,FilePath
out,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 -> FilePath
"Done."
        | FilePath -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null FilePath
o           -> FilePath
e
        | Bool
otherwise        -> FilePath
o
    }