Binding the entire output of an ongoing system process to a variable in Haskell
<p>The following snippet of code executes a <code>grep</code> command and binds the output to <code>stdout'</code>, <code>stderr'</code> and <code>errCode</code> respectively.</p>

<pre><code>main :: IO ()
main = do
    let stdin' = ""
    (errCode, stdout', stderr') &lt;- readProcessWithExitCode "grep" ["search-term" ,"-nr", "/path/to/be/searched"] stdin'
    putStrLn $ "stdout: " ++ stdout'
    putStrLn $ "stderr: " ++ stderr'
    putStrLn $ "errCode: " ++ show errCode
</code></pre>

<p>The problem is that <code>stdout'</code> only captures the <strong>first result</strong> of the search. I think this is because <code>grep</code> is something akin to a spawned process that feeds search results one file by one file until it is finished.</p>

<p><strong>Question:</strong> I need the <strong>entire output</strong> of the standard output of grep to be binded to <code>stdout'</code>. Is this possible in Haskell, and if so, what is an idiomatic way to do it?</p>

<p><strong>EDIT:</strong> It turns out that the issue wasn't as I thought it was. Namely, I had only one file in my directory that wasn't symlinked. I forgot to use <code>-R</code> as an option with <code>grep</code>, and so those symlinks weren't being traversed in the search! The issue has been resolved.</p>