-- 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
    (_,out,err) <- FilePath
-> [FilePath] -> FilePath -> IO (ExitCode, FilePath, FilePath)
readProcessWithExitCode FilePath
binary [] FilePath
src
    let o = FilePath -> FilePath
scrub FilePath
out
        e = FilePath -> FilePath
scrub FilePath
err
    return $ case () of {()
_
        | FilePath -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null FilePath
o Bool -> Bool -> Bool
&& FilePath -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null FilePath
e -> FilePath
"Done."
        | FilePath -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null FilePath
o           -> FilePath
e
        | Bool
otherwise        -> FilePath
o
    }