1 -----------------------------------------------------------------------------
4 -- Copyright : (c) The University of Glasgow 2001
5 -- License : BSD-style (see the file libraries/base/LICENSE)
7 -- Maintainer : libraries@haskell.org
8 -- Stability : provisional
9 -- Portability : portable
11 -- Executing an external command.
13 -----------------------------------------------------------------------------
16 ( system -- :: String -> IO ExitCode
24 #ifdef __GLASGOW_HASKELL__
28 -- ---------------------------------------------------------------------------
32 Computation @system cmd@ returns the exit code
33 produced when the operating system processes the command @cmd@.
35 This computation may fail with
37 * @PermissionDenied@: The process has insufficient privileges to
38 perform the operation.
40 * @ResourceExhausted@: Insufficient resources are available to
41 perform the operation.
43 * @UnsupportedOperation@: The implementation does not support
46 On Windows, 'system' is implemented using Windows's native system
47 call, which ignores the @SHELL@ environment variable, and always
48 passes the command to the Windows command interpreter (@CMD.EXE@ or
49 @COMMAND.COM@), hence Unixy shell tricks will not work.
51 system :: String -> IO ExitCode
52 system "" = ioException (IOError Nothing InvalidArgument "system" "null command" Nothing)
54 withCString cmd $ \s -> do
55 status <- throwErrnoIfMinus1 "system" (primSystem s)
57 0 -> return ExitSuccess
58 n -> return (ExitFailure n)
60 foreign import ccall unsafe "systemCmd" primSystem :: CString -> IO Int