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.hsc,v 1.2 2001/08/17 12:50:34 simonmar Exp $
13 -- Executing a command.
15 -----------------------------------------------------------------------------
18 ( system -- :: String -> IO ExitCode
26 #ifdef __GLASGOW_HASKELL__
32 -- ---------------------------------------------------------------------------
35 -- Computation `system cmd' returns the exit code
36 -- produced when the operating system processes the command `cmd'.
38 -- This computation may fail with
40 -- The process has insufficient privileges to perform the operation.
42 -- Insufficient resources are available to perform the operation.
43 -- UnsupportedOperation
44 -- The implementation does not support system calls.
46 system :: String -> IO ExitCode
47 system "" = ioException (IOError Nothing InvalidArgument "system" "null command" Nothing)
49 withCString cmd $ \s -> do
50 status <- throwErrnoIfMinus1 "system" (primSystem s)
52 0 -> return ExitSuccess
53 n -> return (ExitFailure n)
55 foreign import ccall "systemCmd" unsafe primSystem :: CString -> IO Int