[Haskell-cafe] struggling with blocking shell cmd when using System.Process

Rouan van Dalen rvdalen at yahoo.co.uk
Tue Mar 20 22:51:07 CET 2012


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120320/4c76684a/attachment.htm>


More information about the Haskell-Cafe mailing list