0hc.net Menu
Home Overview
About Menu
Impressum

Process

-- proc0.hs ---------------- module Main where import IAP import System.Process import System.IO main :: IO () main = do (inp,out,err,pid) <- iaProcess "ruby" ["proc0.rb"] hPutStrLn inp "1" a <- hGetLine out hPutStrLn inp a a <- hGetLine out hPutStrLn inp "quit" waitForProcess pid putStrLn a -- iap.hs ---------------- module IAP (iaProcess) where import System.Process (runInteractiveProcess, ProcessHandle) import System.IO (hSetBuffering, BufferMode(LineBuffering), Handle) iaProcess :: String -> [String] -> IO (Handle,Handle,Handle,ProcessHandle) iaProcess pc pa = do (inp,out,err,pid) <- runInteractiveProcess pc pa Nothing Nothing hSetBuffering inp LineBuffering hSetBuffering out LineBuffering hSetBuffering err LineBuffering return (inp,out,err,pid) -- proc0.rb ---------------- module IOStd def ioDo() yield $stdout.flush end def ioPut(*a) print a, "\n" $stdout.flush end def ioPuts(*a) puts a $stdout.flush end def ioPrint(*a) print a $stdout.flush end def ioHDo(hdl) yield hdl.flush end def ioHPut(hdl,*a) hdl.print a, "\n" hdl.flush end def ioHPuts(hdl,*a) hdl.puts a hdl.flush end def ioHPrint(hdl,*a) hdl.print a hdl.flush end end include IOStd loop do a = gets.strip a=="quit" ? exit() : ioPut(a.to_i+1) end
0hc.net    © 2001-2014 Harald Wolfsgruber