[Haskell-cafe] Unexpected results from ExitCode

Peter Schmitz ps.haskell at gmail.com
Thu Nov 4 17:22:10 EDT 2010


Dean,
Thanks very much, that indeed worked.
-- Peter


On Wed, Nov 3, 2010 at 9:16 PM, Dean Herington
<heringtonlacey at mindspring.com> wrote:
> At 8:45 PM -0700 11/3/10, Peter Schmitz wrote:
>>
>> I have a program (test.hs):
>>
>>>  module Main (main) where
>>>  import System.Exit
>>>  main :: IO ExitCode
>>>  main = do
>>>    return (ExitFailure 1)
>>
>>
>> In another program, I invoke it via 'system':
>>
>>>    exitCode <- system ".\\test.exe"
>>>    case (exitCode) of
>>>       ExitFailure failCnt -> do
>>>          putStrLn $ "-- Fail count is: " ++ show failCnt
>>>          exitFailure
>>>       ExitSuccess -> do
>>>          putStrLn $ "-- OK."
>>>          exitSuccess
>>
>>
>> but it always gets ExitSuccess (not ExitFailure failCnt as I expected).
>> (I am running under Windows.)
>>
>> My other use of system (such as with ghc commands) works okay,
>> sometimes getting success, sometimes failure, as expected.
>>
>> Any suggestions much appreciated.
>> Thanks,
>> -- Peter
>
> The value returned by `main` is always discarded.  You need to use
> `exitWith`:
>
> main = exitWith (ExitFailure 1)
>


More information about the Haskell-Cafe mailing list