[Haskell-cafe] Re: Call external program and get stdout

Maurí­cio briqueabraque at yahoo.com
Fri Nov 23 10:22:46 EST 2007


 >>> Hi,
 >>>
 >>> How can I call a program (like, for instance,
 >>> 'grep text *') and get the standard output?
 >>> (...)

 >>http://haskell.org/ghc/docs/latest/html/libraries/process-1.0.0.0/System-Process.html

 > I was using the following:
 > (...)
 >  do (_pIn, pOut, pErr, handle) <- runInteractiveCommand command
 >     -- Wait for the process to finish and store its exit code
 >     exitCode <- waitForProcess handle
 > (...)

I also used runInteractiveCommand, which I found
in the page quoted above. I read the output handle
without waiting for the process to finish, and I
thought runInteractiveCommand would actually not
return before the external process finishes, which
your code showed me to be a wrong prejudice.

That's nice. In my situation, the output of the
program can be really big, so I prefer not to wait
for it to finish before I do stuff with the
output, but I'll probably use your code in most
situations, since I can check the exit code before
doing anything.

Best,
Maurício



More information about the Haskell-Cafe mailing list