[Haskell] runProcess with out=err

Ian Lynagh igloo at earth.li
Thu Jul 28 09:35:23 EDT 2005


Hi,

With the below code (compiled by ghc) I get
"a.out: thread blocked indefinitely".

Changing the second (Just hout) to Nothing makes it run as expected.

If I dup fdout to get an fderr and then try to also convert that to
a handle then I get "a.out: openFile: resource busy (file is locked)".

Is there a way to write this with stdout and stderr going to the same
handle?

-------------------
module Main (main) where

import System.Posix (openFd, defaultFileFlags, stdFileMode,
                     OpenMode(ReadOnly, WriteOnly), fdToHandle)
import System.Process (runProcess, waitForProcess)

main :: IO ()
main = exec "echo" ["foo"] "in" "out"

exec :: String -> [String] -> FilePath -> FilePath -> IO ()
exec c args inp out
 = do fdin <- openFd inp ReadOnly Nothing defaultFileFlags
      fdout <- openFd out WriteOnly (Just stdFileMode) defaultFileFlags
      hin <- fdToHandle fdin
      hout <- fdToHandle fdout
      ph <- runProcess c args Nothing Nothing
                       (Just hin) (Just hout) (Just hout)
      waitForProcess ph >>= print
-------------------


Thanks
Ian



More information about the Haskell mailing list