Binding the entire output of an ongoing system process to a variable in Haskell

ε祈祈猫儿з 提交于 2020-01-14 04:07:13

问题


The following snippet of code executes a grep command and binds the output to stdout', stderr' and errCode respectively.

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

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

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

EDIT: 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 -R as an option with grep, and so those symlinks weren't being traversed in the search! The issue has been resolved.

来源:https://stackoverflow.com/questions/37197388/binding-the-entire-output-of-an-ongoing-system-process-to-a-variable-in-haskell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!