runInteractiveProcess is broken
Peter Simons
simons at cryp.to
Tue Oct 26 16:42:54 EDT 2004
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
More information about the Glasgow-haskell-users
mailing list