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
26 #ifdef __GLASGOW_HASKELL__
34 -- ---------------------------------------------------------------------------
38 Computation @system cmd@ returns the exit code
39 produced when the operating system processes the command @cmd@.
41 This computation may fail with
43 * @PermissionDenied@: The process has insufficient privileges to
44 perform the operation.
46 * @ResourceExhausted@: Insufficient resources are available to
47 perform the operation.
49 * @UnsupportedOperation@: The implementation does not support
52 On Windows, 'system' is implemented using Windows's native system
53 call, which ignores the @SHELL@ environment variable, and always
54 passes the command to the Windows command interpreter (@CMD.EXE@ or
55 @COMMAND.COM@), hence Unixy shell tricks will not work.
58 system :: String -> IO ExitCode
59 system "" = ioException (IOError Nothing InvalidArgument "system" "null command" Nothing)
61 withCString cmd $ \s -> do
62 status <- throwErrnoIfMinus1 "system" (primSystem s)
64 0 -> return ExitSuccess
65 n -> return (ExitFailure n)
67 foreign import ccall unsafe "systemCmd" primSystem :: CString -> IO Int