
Neither of these functions returns the return code of the external process as promised: import System.IO hiding ( catch, try ) import System.Process import Control.Concurrent sleep :: Int -> IO () sleep n = threadDelay (abs(n) * 1000000) test1 :: IO () test1 = do (_,_,_, pid) <- runInteractiveProcess "/usr/bin/sleep" ["1"] Nothing Nothing sleep 5 rc <- waitForProcess pid print rc -- *Main> test1 -- *** Exception: waitForProcess: does not exist (No child processes) test2 :: IO () test2 = do (_,_,_, pid) <- runInteractiveProcess "/usr/bin/sleep" ["1"] Nothing Nothing sleep 5 rc <- getProcessExitCode pid print rc -- *Main> test2 -- Nothing I'm using the ghc from CVS-HEAD on Linux/x86. Peter

I managed to get runInteractiveProcess to work after all. Here is the code:
import System.Posix.Signals import System.IO hiding ( catch, try ) import System.Exit ( ExitCode(..) ) import System.Process import Control.Concurrent import Child -- http://cryp.to/child/Child.hs
test :: IO () test = do installHandler sigCHLD (Catch (return ())) Nothing (_,_,_, pid) <- runInteractiveProcess "/usr/bin/sleep" ["1"] Nothing Nothing sleep 5 safeGetExitCode pid >>= print
safeGetExitCode :: ProcessHandle -> IO ExitCode safeGetExitCode pid = timeout (10*1000000) (getRCLoop) >>= maybe (fail "timeout while waiting for external process") return where getRCLoop = getProcessExitCode pid >>= maybe (sleep 1 >> getRCLoop) return
The culprit seems to be: If you don't accept sigCHLD, you lose. If you use waitForProcess, you lose. Threaded RTS or not doesn't seem to make a difference. Peter
participants (1)
-
Peter Simons