That's not going to be sufficient; you could end up in a deadlock by not flushing the output buffer of the child process. Have a look at the implementation of readProcess to see how to deal with some of these tricky issues in the lazy I/O world:<br><div><br></div><div><a href="http://hackage.haskell.org/package/process-1.2.0.0/docs/src/System-Process.html#readProcess">http://hackage.haskell.org/package/process-1.2.0.0/docs/src/System-Process.html#readProcess</a><br></div><br><div class="gmail_quote">On Thu Dec 11 2014 at 6:40:54 PM Derek McLoughlin <<a href="mailto:derek.mcloughlin@gmail.com">derek.mcloughlin@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Something like this would work:<div><br></div><div><div>import System.Process</div><div>import System.IO</div><div>import System.Exit</div><div><br></div><div>readExecOutput :: String -> [String] -> IO ()    </div><div>readExecOutput cmdName cmdOptions = do</div><div>    (_, Just hOut, _, jHandle) <-</div><div>        createProcess (proc cmdName cmdOptions)</div><div>           { cwd = Just "."</div><div>           , std_out = CreatePipe</div><div>           }</div><div>    exitCode <- waitForProcess jHandle</div><div>    exec_output <- hGetContents hOut </div><div>    case exitCode of</div><div>        ExitSuccess -> putStr $ "Success!\n" ++ exec_output</div><div>        _           -> putStrLn "Command failed"</div><div><br></div><div><br></div><div>Derek.</div></div></div><div dir="ltr"><div><br>On Thursday, 11 December 2014 13:29:34 UTC, Ernesto Rodriguez  wrote:</div></div><div dir="ltr"><div><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>Hi Michael, <br><br></div>Thank you for your answer. Conduits certainly are the best approach, but the output I am going to read is very short and the external program will only be called once or twice per execution so I think Lazy IO won't be problematic here.<br><br></div>Best regards,<br><br></div>Ernesto<br></div></blockquote></div></div><div dir="ltr"><div><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="gmail_quote">On Thu, Dec 11, 2014 at 10:18 AM, Michael Snoyman <span dir="ltr"><<a>mic...@snoyman.com</a>></span> wrote:<br></div></div></blockquote></div></div><div dir="ltr"><div><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You can use readProcess[1], but it has some downsides:<div><br></div><div>1. Can't specify all options to CreateProcess, e.g., working directory and environment variables.</div><div>2. Relies on lazy I/O</div><div><br></div><div>I use Data.Conduit.Process[2] for this kind of thing, which has a full tutorial[3]. However, it *does* involve non-base dependencies.<br><br><div>[1] <a href="http://www.stackage.org/haddock/2014-12-10-ghc78-exc/process-1.2.0.0/System-Process.html#v:readProcess" target="_blank">http://www.stackage.org/<u></u>haddock/2014-12-10-ghc78-exc/<u></u>process-1.2.0.0/System-<u></u>Process.html#v:readProcess</a></div></div><div>[2] <a href="http://www.stackage.org/haddock/2014-12-10-ghc78-exc/conduit-extra-1.1.4.2/Data-Conduit-Process.html" target="_blank">http://www.stackage.org/<u></u>haddock/2014-12-10-ghc78-exc/<u></u>conduit-extra-1.1.4.2/Data-<u></u>Conduit-Process.html</a></div><div>[3] <a href="https://www.fpcomplete.com/user/snoyberg/library-documentation/data-conduit-process?show=tutorials" target="_blank">https://www.fpcomplete.<u></u>com/user/snoyberg/library-<u></u>documentation/data-conduit-<u></u>process?show=tutorials</a></div><br></blockquote></div></div></blockquote></div></div><div dir="ltr"><div><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><div><div>On Thu Dec 11 2014 at 11:11:12 AM Ernesto Rodriguez <<a>ne...@netowork.me</a>> wrote:<br></div></div></div></blockquote></div></div></blockquote></div></div><div dir="ltr"><div><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr"><div><div>Dear All,<br><br></div>I have a program which invokes an external program via exec. I wish to capture the standard output of the program without using external (temporary) files. Is it possible to create an in memory handle which I can tell exec to use as standard output of the invoked program. It would be great if it can be done without any extra dependencies.<br><br></div>Best,<br clear="all"><div><div><div><br>-- <br><div><div dir="ltr"><div>Ernesto Rodriguez<br></div><div><br></div><div>Masters Student</div><div>Computer Science</div><div>Utrecht University</div><div><br></div><div><a href="http://www.netowork.me" target="_blank">www.netowork.me</a></div><div><a href="http://github.com/netogallo" target="_blank">github.com/netogallo</a></div><div><br></div><div><br></div></div></div>
</div></div></div></div></div></div>
______________________________<u></u><u></u>_________________<br>
Haskell-Cafe mailing list<br>
</blockquote></div></blockquote></div></div></blockquote></div></div><div dir="ltr"><div><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><a>Haskel...@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/<u></u>mailman<u></u>/listinfo/haskell-cafe</a><br>
</blockquote></div>
</blockquote></div></div></blockquote></div></div><div dir="ltr"><div><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div><br><br clear="all"><br>-- <br><div><div dir="ltr"><div>Ernesto Rodriguez<br></div><div><br></div><div>Masters Student</div><div>Computer Science</div><div>Utrecht University</div><div><br></div><div><a href="http://www.netowork.me" target="_blank">www.netowork.me</a></div><div><a href="http://github.com/netogallo" target="_blank">github.com/netogallo</a></div><div><br></div><div><br></div></div></div>
</div></blockquote></div></div></blockquote></div>