[nhc-bugs] System.system

Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk
Wed Feb 11 12:07:00 EST 2004


Ian Lynagh <igloo at earth.li> writes:

> In src/prelude/System/SystemFun.hs the OS's system function is called to
> implement System.system. However, the various checks are not done and
> WEXITSTATUS is not applied as appropriate.

> main = mapM_ f [0..5]
> 
> f :: Int -> IO ()
> f i = do x <- system $ "exit " ++ show i
>          print x
> -----8<----------8<----------8<----------8<-----
> ExitSuccess
> ExitFailure 256
> ExitFailure 512
> ExitFailure 768
> ExitFailure 1024
> ExitFailure 1280

Thanks for the bug report.  This has been noticed before.  However,
the Haskell'98 Libraries Report states simply that:

    "Computation /system cmd/ returns the exit code produced when
     the operating system processes the command /cmd/".
and
    "The exact interpretation of [exit] /code/ is operating system dependent".

It does not define any particular mapping of ExitFailure codes, and
in particular it makes no mention of any unix shell.  nhc98 directly
passes on the exit status provided by the operating system call
'system()', whereas ghc converts that value into the equivalent
value that would be seen in some shells.  As far as I can see, both
behaviours are permitted.

Nonetheless, this is an unfortunate incompatibility between compilers,
so probably worth changing.

Regards,
    Malcolm


More information about the Nhc-bugs mailing list