-- SpawnEchoShiftLetters.hs -- -- Test program for popen function. -- This is essentially the same program as SpawnEchoShiftLetters.c, -- written to use the Haskell interface (POpen.hs) to spawnProc.c module SpawnEchoShiftLetters where import Win32.POpen (popen, popenEnvDir) import System.Environment( getArgs ) import System.Exit( ExitCode(ExitSuccess,ExitFailure) ) import Data.Char( isSpace ) main :: IO () main = do { argv <- getArgs ; mainBody argv ; return () } mainBody :: [String] -> IO String mainBody argv = do { (res, errs, pid) <- popen "EchoShiftLetters.exe" [] (Just "abcdefghijklmnopqrstuvwxyz") ; putStrLn ("pid: "++(show pid)) ; putStrLn ("input: "++"abcdefghijklmnopqrstuvwxyz") ; putStrLn ("errout: "++errs) ; putStrLn ("stdout: "++res) ; return res } -- Function for running program within Hugs runMain :: String -> IO ExitCode runMain cmdline = do { let argv = breakAll isSpace cmdline ; res <- mainBody argv ; let ec = if null res then (ExitFailure 2) else ExitSuccess ; if (ec /= ExitSuccess) then (putStrLn $ "HXml Parser exit: "++show ec) else (return ()) ; return ec } -- |Break list into a list of sublists, separated by element -- satisfying supplied condition. breakAll :: (a -> Bool) -> [a] -> [[a]] breakAll _ [] = [] breakAll p s = let (h,s') = break p s in h : breakAll p (drop 1 s') -- Quick run test case runTest = runMain ""