struggling with blocking shell cmd when using System.Process

Hi Everyone, I am strugling to get the following code to work correctly and I'm hoping someone will be able to shed some light as to why the code is behaving as it does: {-| runs the supplied command and args as a SHELL command -} runShell :: String -> IO (String, ExitCode) runShell shellCmd = do (_, Just hOut, Just hErr, hProcess) <- createProcess (shell shellCmd) { std_out = CreatePipe, std_err = CreatePipe } exitCode <- waitForProcess hProcess outTxt <- hGetContents hOut errTxt <- hGetContents hErr return $ (outTxt ++ errTxt, exitCode) If I try to su the runShell function with the following command, it simply blocks forever: git --no-pager blame <your git file here> but if I do: git status The runShell function works as expected. Can someone shed some light on why the 'git blame' command blocks? Interrestingly enough, if I remove the waitForProcess action, the 'git blame' command starts working as expected, but I no longer have my blocking behaviour, waiting for the command to finish and return the ExitCode. Regards Rouan

Hi Everyone, I forgot to say, I am running GHC 7.2.2 on Windows7 x64. Regards.

On Tue, Mar 20, 2012 at 17:51, Rouan van Dalen
If I try to su the runShell function with the following command, it simply blocks forever:
git --no-pager blame <your git file here>
but if I do:
git status
The runShell function works as expected. Can someone shed some light on why the 'git blame' command blocks? Interrestingly enough, if I
You're trying to run the command and then collect all the output afterward; this requires the OS to buffer potentially very large amounts of data, whereas most OSes cache only a very small amount over a pipe. You will need to read the data as the command runs to avoid blocking, then close the process once you have read EOF. -- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms
participants (2)
-
Brandon Allbery
-
Rouan van Dalen