1 -----------------------------------------------------------------------------
4 -- Copyright : (c) The University of Glasgow 2001
5 -- License : BSD-style (see the file libraries/core/LICENSE)
7 -- Maintainer : libraries@haskell.org
8 -- Stability : provisional
9 -- Portability : portable
11 -- $Id: Cmd.hs,v 1.3 2002/04/24 16:31:45 simonmar Exp $
13 -- Executing a command.
15 -----------------------------------------------------------------------------
18 ( system -- :: String -> IO ExitCode
26 #ifdef __GLASGOW_HASKELL__
30 -- ---------------------------------------------------------------------------
33 -- Computation `system cmd' returns the exit code
34 -- produced when the operating system processes the command `cmd'.
36 -- This computation may fail with
38 -- The process has insufficient privileges to perform the operation.
40 -- Insufficient resources are available to perform the operation.
41 -- UnsupportedOperation
42 -- The implementation does not support system calls.
44 system :: String -> IO ExitCode
45 system "" = ioException (IOError Nothing InvalidArgument "system" "null command" Nothing)
47 withCString cmd $ \s -> do
48 status <- throwErrnoIfMinus1 "system" (primSystem s)
50 0 -> return ExitSuccess
51 n -> return (ExitFailure n)
53 foreign import ccall unsafe "systemCmd" primSystem :: CString -> IO Int