summaryrefslogtreecommitdiff
path: root/utils/runghc
diff options
context:
space:
mode:
authorSimon Marlow <simonmar@microsoft.com>2008-02-07 14:58:30 +0000
committerSimon Marlow <simonmar@microsoft.com>2008-02-07 14:58:30 +0000
commit752169f4ea14c0fd890ac55af5395bd1672751ea (patch)
treeda21e34fdcf6d739b9cb486e78ddb298d37fae17 /utils/runghc
parenta411ca6bf32a14cc656c2c981c5cf6e37cfd3d64 (diff)
downloadhaskell-752169f4ea14c0fd890ac55af5395bd1672751ea.tar.gz
Allow runghc to take input from stdin, just like Ruby & Python
Diffstat (limited to 'utils/runghc')
-rw-r--r--utils/runghc/runghc.hs21
1 files changed, 16 insertions, 5 deletions
diff --git a/utils/runghc/runghc.hs b/utils/runghc/runghc.hs
index 244c98f972..458861ea65 100644
--- a/utils/runghc/runghc.hs
+++ b/utils/runghc/runghc.hs
@@ -27,13 +27,14 @@ import System.IO
import Data.List
import System.Exit
import Data.Char
+import System.Directory ( removeFile )
+import Control.Exception ( bracket )
+import System.Directory ( findExecutable, getTemporaryDirectory )
#ifdef USING_COMPAT
import Compat.RawSystem ( rawSystem )
-import Compat.Directory ( findExecutable )
#else
import System.Cmd ( rawSystem )
-import System.Directory ( findExecutable )
#endif
main :: IO ()
@@ -59,7 +60,17 @@ doIt :: String -> [String] -> IO ()
doIt ghc args = do
let (ghc_args, rest) = getGhcArgs args
case rest of
- [] -> dieProg usage
+ [] -> do
+ -- behave like typical perl, python, ruby interpreters:
+ -- read from stdin
+ tmpdir <- getTemporaryDirectory
+ bracket
+ (openTempFile tmpdir "runghcXXXX.hs")
+ (\(filename,_) -> removeFile filename)
+ $ \(filename,h) -> do
+ getContents >>= hPutStr h
+ hClose h
+ doIt ghc (ghc_args ++ [filename])
filename : prog_args -> do
let c1 = ":set prog " ++ show filename
c2 = ":main " ++ show prog_args
@@ -90,6 +101,6 @@ dieProg msg = do
hPutStrLn stderr (p ++ ": " ++ msg)
exitWith (ExitFailure 1)
-usage :: String
-usage = "syntax: runghc [-f GHC-PATH | --] [GHC-ARGS] [--] FILE ARG..."
+-- usage :: String
+-- usage = "syntax: runghc [-f GHC-PATH | --] [GHC-ARGS] [--] FILE ARG..."