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, -- :: FilePath -> [String] -> IO ExitCode
24 #ifdef __GLASGOW_HASKELL__
37 import System (system)
40 -- ---------------------------------------------------------------------------
44 Computation @system cmd@ returns the exit code
45 produced when the operating system processes the command @cmd@.
47 This computation may fail with
49 * @PermissionDenied@: The process has insufficient privileges to
50 perform the operation.
52 * @ResourceExhausted@: Insufficient resources are available to
53 perform the operation.
55 * @UnsupportedOperation@: The implementation does not support
58 On Windows, 'system' is implemented using Windows's native system
59 call, which ignores the @SHELL@ environment variable, and always
60 passes the command to the Windows command interpreter (@CMD.EXE@ or
61 @COMMAND.COM@), hence Unixy shell tricks will not work.
63 #ifdef __GLASGOW_HASKELL__
64 system :: String -> IO ExitCode
65 system "" = ioException (IOError Nothing InvalidArgument "system" "null command" Nothing)
67 withCString cmd $ \s -> do
68 status <- throwErrnoIfMinus1 "system" (primSystem s)
70 0 -> return ExitSuccess
71 n -> return (ExitFailure n)
73 foreign import ccall unsafe "systemCmd" primSystem :: CString -> IO Int
74 #endif /* __GLASGOW_HASKELL__ */
76 -- ---------------------------------------------------------------------------
79 -- rawSystem is in a separate file, so we can #include it various places.
80 #include "RawSystem.hs-inc"