Laszlo Nemeth writes:
> 
> The code enclosed, works as expected for 2.10, works for
> proto-3.03-15-Jul but breaks for 3.03 (latest from the CVS). The
> problems seems to be something to do with handles: you write something
> to it, but it doesn't go to the pipe.
> 

There's a couple of problems here:

- the problem with hClose not closing the underlying file descriptor
  has been fixed (and quite a long time ago too), so, instead of,

                     fd <- handleToFd inH
                     fdClose fd

  do
                     hClose inH

  A little bit nicer, and should do the right thing in the presence
  of Handle buffering.

- it looks as if you're working on a platform that gives you back
  a duplex pipe via pipe() (Solaris?), since the version of 'exec'
  you're gets the input and output fd's wrong (I thought I sent
  you guys a fixed version of this a while ago..?) Instead, try
  using the version appended instead and have another go.

hth,
--sigbjorn


exec :: String -> [String] -> IO (Handle, Handle)
exec cmd args = do
  (cReadFd, pWriteFd) <- createPipe
  (pReadFd, cWriteFd) <- createPipe
  child               <- forkProcess
  case child of
   Just x  -> do -- parent
     fdClose cReadFd
     fdClose cWriteFd
     pWriteH <- fdToHandle pWriteFd
     pReadH  <- fdToHandle pReadFd
     hSetBuffering pWriteH NoBuffering
     hSetBuffering pReadH  NoBuffering
     return (pWriteH, pReadH)
   Nothing -> do -- child
     -- replace stdin, stdout with read and write end of the pipe.
     dupTo cReadFd  stdInput
     dupTo cWriteFd stdOutput
     fdClose pReadFd
     fdClose pWriteFd
     executeFile cmd True args Nothing
     fdClose cReadFd
     fdClose cWriteFd
     exitWith ExitSuccess

Reply via email to