summaryrefslogtreecommitdiff
path: root/libraries/base/System/Cmd.hsc
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/base/System/Cmd.hsc')
-rw-r--r--libraries/base/System/Cmd.hsc55
1 files changed, 55 insertions, 0 deletions
diff --git a/libraries/base/System/Cmd.hsc b/libraries/base/System/Cmd.hsc
new file mode 100644
index 0000000000..2deb48cd00
--- /dev/null
+++ b/libraries/base/System/Cmd.hsc
@@ -0,0 +1,55 @@
+-----------------------------------------------------------------------------
+--
+-- Module : System.Cmd
+-- Copyright : (c) The University of Glasgow 2001
+-- License : BSD-style (see the file libraries/core/LICENSE)
+--
+-- Maintainer : libraries@haskell.org
+-- Stability : provisional
+-- Portability : portable
+--
+-- $Id: Cmd.hsc,v 1.1 2001/06/28 14:15:04 simonmar Exp $
+--
+-- Executing a command.
+--
+-----------------------------------------------------------------------------
+
+module System.Cmd
+ ( system -- :: String -> IO ExitCode
+ ) where
+
+import Prelude
+
+import System.Exit
+import Foreign.C
+
+#ifdef __GLASGOW_HASKELL__
+import GHC.IOBase
+#endif
+
+#include "HsCore.h"
+
+-- ---------------------------------------------------------------------------
+-- system
+
+-- Computation `system cmd' returns the exit code
+-- produced when the operating system processes the command `cmd'.
+
+-- This computation may fail with
+-- PermissionDenied
+-- The process has insufficient privileges to perform the operation.
+-- ResourceExhausted
+-- Insufficient resources are available to perform the operation.
+-- UnsupportedOperation
+-- The implementation does not support system calls.
+
+system :: String -> IO ExitCode
+system "" = ioException (IOError Nothing InvalidArgument "system" "null command" Nothing)
+system cmd =
+ withUnsafeCString cmd $ \s -> do
+ status <- throwErrnoIfMinus1 "system" (primSystem s)
+ case status of
+ 0 -> return ExitSuccess
+ n -> return (ExitFailure n)
+
+foreign import ccall "systemCmd" unsafe primSystem :: UnsafeCString -> IO Int