[Haskell-cafe] Re: Execution of external command

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Thu Dec 13 13:08:44 EST 2007


On Thu, 2007-12-13 at 19:38 +0200, Yitzchak Gale wrote:

> Simon Marlow wrote:
> > It could deadlock if the script produces enough stderr to fill up its pipe
> > buffer
> 
> If we need to worry about that, then what about this:
> 
> (_,h,e,_) <- runInteractiveCommand "script params"
> forkIO (hGetContents e >>= evaluate . length)
> output <- hGetContents h
> 
> It requires -threaded in the case of a huge amount

It does not require -threaded. GHC's single threaded rts has always been
able to cope with multiple haskell threads that want to do file/network
IO.

> of output to both stdout and stderr; maybe that isn't
> good for Bulat. If that is a problem, you can read a chunk
> at a time and call yield - but that is getting messier.

Calling yield ends up busy waiting if there is no output available from
either stdout or stderr. It also requires threads so it's not a portable
solution.

Something simple would be to allow attaching a pipe to just the stdout
and redirecting stderr elsewhere, or connecting both stdout and stderr
to the same output pipe. runProcess allows substituting any of
stdin/stdout/stderr for other Handles and runInteractiveProcess
substitutes them all for pipes. What we need is something in between
that allows substituting some for given Handles and connecting others to
pipes.

Duncan



More information about the Haskell-Cafe mailing list