runProcess with out=err
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
Ian Lynagh writes:
With the below code (compiled by ghc) I get "a.out: thread blocked indefinitely".
You need to compile with '-threaded' to avoid this problem. Unfortunately, this doesn't mean that your program will actually work. ;-) GHC 6.4 produces a binary that waits forever. When compiling with the current GHC from CVS, everything is good: $ ghc-6.5 -threaded --make test.hs && ./a.out Chasing modules from: test.hs [1 of 1] Compiling Main ( test.hs, test.o ) Linking ... ExitSuccess Peter
On Thu, Jul 28, 2005 at 04:35:10PM +0200, Peter Simons wrote:
Ian Lynagh writes:
With the below code (compiled by ghc) I get "a.out: thread blocked indefinitely".
You need to compile with '-threaded' to avoid this problem.
Unfortunately, this doesn't mean that your program will actually work. ;-) GHC 6.4 produces a binary that waits forever. When compiling with the current GHC from CVS, everything is good:
Hmm, I had assumed that this was not working because of the file locking stuff in the report. It works both with and without -threaded with CVS GHC for me. So, is this a bug in CVS GHC or in 6.4? Thanks Ian
participants (2)
-
Ian Lynagh -
Peter Simons