[Haskell-cafe] How to waitForProcess?

Brandon Allbery allbery.b at gmail.com
Wed Sep 5 07:34:00 CEST 2012


On Tue, Sep 4, 2012 at 9:39 PM, Mike Ledger <eleventynine at gmail.com> wrote:

> You might have to use hGetContents, then waitForProcess, and then
> terminateProcess -- you can then check if the process is indeed terminated
> using getProcessExitCode.


Er?  When waitForProcess returns the process is dead; there's nothing to
terminateProcess.  If you do it the other way around then you may not get
full output.

For starters, I would not build up the CreateProcess record directly but
use the "proc" record and override it with your I/O definitions.  I've been
bit by this before (I think some older version of System.Process lacked
useful predefined records?).

There is a severe gotcha here if you do things naively (like your example
code does).  If there is more output than will fit in a pipe, *no* ordering
of read / wait in a single thread will work without deadlocking; you have
no choice but to do the read in a separate thread.  This is not a Haskell
issue, it is how pipes work on POSIX systems.  (I don't know if Windows has
the same problem.)

-- 
brandon s allbery                                      allbery.b at gmail.com
wandering unix systems administrator (available)     (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120904/61233dc0/attachment.htm>


More information about the Haskell-Cafe mailing list