System

-- | <https://www.altocumulus.org/haskell98-report-html/system.html>
module System where
import Prelude
import PreludeIO
import IO0
import MonadicIO0

data ExitCode = ExitSuccess | ExitFailure Int deriving (Eq,Ord,Show,Read)
--instance Show ExitCode

getArgs :: IO [String]
getProgName :: IO String

getArgs = return (drop 1 progLine)
getProgName = return (head progLine)

exitWith :: ExitCode -> IO a
exitWith ExitSuccess = primExit 0
exitWith (ExitFailure n) = primExit n

exitFailure :: IO a
exitFailure = primExit 1 -- system dependent...

--getEnv var = maybe (ioError (IOE DoesNotExistError var)) return (getenv var)
getEnv = primGetEnv

system cmd = fmap exitCode (primRawSystem "bash" ["bash","-c",cmd]) -- !! hmm
  where
    exitCode 0 = ExitSuccess
    exitCode n = ExitFailure n