runInteractiveProcess, confused

Simon Marlow simonmar at microsoft.com
Tue May 24 11:04:43 EDT 2005


On 18 May 2005 14:47, Frederik Eaton wrote:

> When I run the following line in ghci:
> 
> Prelude System.Process Control.Concurrent System.IO> do { (inp, out,
> err, ph) <- runInteractiveProcess "cat" [] Nothing Nothing; forkIO
> (do hPutStr inp "this\nis\na\ntest\n"; hClose inp); waitForProcess ph
> }   
> 
> ... it doesn't terminate. I'm following the example in the
> System.Process documentation. But I would think that since I close
> 'inp', "cat" would terminate. Also, I don't see the expected output.

This example won't work inside GHCi, because GHCi isn't compiled with
-threaded: the -threaded option is required to get a version of
waitForProcess that doesn't block other threads in a multithreaded
program.

The only reason GHCi isn't compiled with -threaded is because I'm being
conservative; the threaded RTS introduces a lot more complexity and
hasn't been shaken down as much as the single-threaded RTS.  

If you compile GHC up yourself you can fix it by adding "GhcStage2HcOpts
+= -threaded" to mk/build.mk before building.

In a future release of GHC we'll do this by default.

Cheers,
	Simon


More information about the Glasgow-haskell-users mailing list