
Hello George, Thursday, September 21, 2006, 7:44:22 AM, you wrote:
sh :: String -> String -> IO String sh cmd = \input -> do (stdin, stdout, _, pid) <- runInteractiveCommand cmd forkIO $ hPutStr stdin input >> hClose stdin -- get exit status to prevent zombie accumulation forkIO $ waitForProcess pid >> return () hGetContents stdout
1. when 'main' finishes, all the threads created by forkIO, silently dies. typically you need to wait until they are finished. ghc libraries don't provide any provision for it, they are too low-level. you can consider writing your own simple wrapper using MVar: myFork action = do v <- newEmptyMVar forIO $ action >>= putMVar v return v finishHim v = takeMVar v which also returns value returned by action. usage: subProcess <- myFork $ do-something-here ... finishHim subProcess or you can use some simple libraries which use more developed solutions of this problem: http://freearc.narod.ru/Process.tar.gz (my own) http://www-i2.informatik.rwth-aachen.de/~stolz/Haskell/CA.hs 2. afaiu, you don't want to wait for process finishing before calling getContents? in this case you need to collect all 'pids' returned by myFork function in some list and finish them all before main returns. or, better, develop more complex interface that will allow to kill processes whose output is no more required, in order to help 'head'-like processes also look at http://www.haskell.org/~petersen/haskell/popenhs/popenhs-1.00.0.tar.gz http://www.volker-wysk.de/hsshellscript/dist/hsshellscript-2.5.0.tar.gz and file i attached also, look at "Tackling the awkward squad: monadic input/output, concurrency, exceptions, and foreign-language calls in Haskell" http://research.microsoft.com/Users/simonpj/papers/marktoberdorf/marktoberdo... paper, which is a definitive source of information about GHC concurrency implementation -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com