[Haskell] runProcess with out=err
simonmar at microsoft.com
Mon Aug 1 10:29:13 EDT 2005
On 28 July 2005 14:35, Ian Lynagh wrote:
> 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
> 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
This bug was fixed in rev. 1.12 of System.Process.Internals, and has
been merged into the 6.4 branch.
More information about the Libraries