[project @ 2002-07-16 16:08:58 by ross]
[packages/old-locale.git] / System / Cmd.hs
1 -----------------------------------------------------------------------------
2 -- |
3 -- Module : System.Cmd
4 -- Copyright : (c) The University of Glasgow 2001
5 -- License : BSD-style (see the file libraries/base/LICENSE)
6 --
7 -- Maintainer : libraries@haskell.org
8 -- Stability : provisional
9 -- Portability : portable
10 --
11 -- Executing an external command.
12 --
13 -----------------------------------------------------------------------------
14
15 module System.Cmd
16 ( system -- :: String -> IO ExitCode
17 ) where
18
19 import Prelude
20
21 import System.Exit
22 #ifndef __HUGS__
23 import Foreign.C
24 #endif
25
26 #ifdef __GLASGOW_HASKELL__
27 import GHC.IOBase
28 #endif
29
30 #ifdef __HUGS__
31 import Hugs.System
32 #endif
33
34 -- ---------------------------------------------------------------------------
35 -- system
36
37 {-|
38 Computation @system cmd@ returns the exit code
39 produced when the operating system processes the command @cmd@.
40
41 This computation may fail with
42
43 * @PermissionDenied@: The process has insufficient privileges to
44 perform the operation.
45
46 * @ResourceExhausted@: Insufficient resources are available to
47 perform the operation.
48
49 * @UnsupportedOperation@: The implementation does not support
50 system calls.
51
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.
56 -}
57 #ifndef __HUGS__
58 system :: String -> IO ExitCode
59 system "" = ioException (IOError Nothing InvalidArgument "system" "null command" Nothing)
60 system cmd =
61 withCString cmd $ \s -> do
62 status <- throwErrnoIfMinus1 "system" (primSystem s)
63 case status of
64 0 -> return ExitSuccess
65 n -> return (ExitFailure n)
66
67 foreign import ccall unsafe "systemCmd" primSystem :: CString -> IO Int
68 #endif /* __HUGS__ */