program execution and laziness

I'm having a problem with program execution in win32 which seems to be tied to laziness. The function I'm using is: runCmd cmd outdir dir base ext = do let argv = words cmd (i,o,e,p) <- runInteractiveProcess (head argv) (drop 1 argv) Nothing Nothing hClose i out <- hGetContents o -- print out x <- waitForProcess p hClose o hClose e case x of ExitSuccess -> return 0 (ExitFailure n) -> return n this is hanging indefinitely when I run it in win32. If I add in the print statement (commented out above) it works fine! So I can only imagine that waitForProcess is hanging when I haven't drained the stdout stream. How can I force hGetContents to be strict (or at least to completely process the stream prior to the waitForProcess command)? Tim Newsham http://www.thenewsh.com/~newsham/

Hello Tim, Thursday, September 14, 2006, 5:32:24 AM, you wrote:
out <- hGetContents o -- print out
How can I force hGetContents to be strict (or at least to completely process the stream prior to the waitForProcess command)?
return $! last out -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

Bulat Ziganshin
out <- hGetContents o -- print out
How can I force hGetContents to be strict (or at least to completely process the stream prior to the waitForProcess command)?
return $! last out
You will still get into trouble if the command produces copious error output. See runCommand in http://happs.org/HAppS/src/HAppS/Util/Common.hs for a GPL'd solution. -- Feri.

On Wed, 13 Sep 2006, Tim Newsham wrote:
I'm having a problem with program execution in win32 which seems to be tied to laziness. The function I'm using is:
runCmd cmd outdir dir base ext = do let argv = words cmd (i,o,e,p) <- runInteractiveProcess (head argv) (drop 1 argv) Nothing Nothing hClose i out <- hGetContents o -- print out x <- waitForProcess p hClose o hClose e case x of ExitSuccess -> return 0 (ExitFailure n) -> return n
Btw. you may want to enclose starting the process and closing the file handles in a 'bracket'.
participants (4)
-
Bulat Ziganshin
-
Ferenc Wagner
-
Henning Thielemann
-
Tim Newsham