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
17 #ifdef __GLASGOW_HASKELL__
18 rawSystem, -- :: String -> IO ExitCode
24 #ifdef __GLASGOW_HASKELL__
35 import System (system)
38 -- ---------------------------------------------------------------------------
42 Computation @system cmd@ returns the exit code
43 produced when the operating system processes the command @cmd@.
45 This computation may fail with
47 * @PermissionDenied@: The process has insufficient privileges to
48 perform the operation.
50 * @ResourceExhausted@: Insufficient resources are available to
51 perform the operation.
53 * @UnsupportedOperation@: The implementation does not support
56 On Windows, 'system' is implemented using Windows's native system
57 call, which ignores the @SHELL@ environment variable, and always
58 passes the command to the Windows command interpreter (@CMD.EXE@ or
59 @COMMAND.COM@), hence Unixy shell tricks will not work.
61 #ifdef __GLASGOW_HASKELL__
62 system :: String -> IO ExitCode
63 system "" = ioException (IOError Nothing InvalidArgument "system" "null command" Nothing)
65 withCString cmd $ \s -> do
66 status <- throwErrnoIfMinus1 "system" (primSystem s)
68 0 -> return ExitSuccess
69 n -> return (ExitFailure n)
71 foreign import ccall unsafe "systemCmd" primSystem :: CString -> IO Int
74 The same as 'system', but bypasses the shell. Will behave more portably between
75 systems, because there is no interpretation of shell metasyntax.
78 rawSystem :: String -> IO ExitCode
79 rawSystem "" = ioException (IOError Nothing InvalidArgument "rawSystem" "null command" Nothing)
81 withCString cmd $ \s -> do
82 status <- throwErrnoIfMinus1 "rawSystem" (primRawSystem s)
84 0 -> return ExitSuccess
85 n -> return (ExitFailure n)
87 foreign import ccall unsafe "rawSystemCmd" primRawSystem :: CString -> IO Int
89 #endif /* __GLASGOW_HASKELL__ */