Mircea Draghicescu wrote:
> [...]
> What is the easiest way to run an external command from a Haskell
> program and capture its output (stdout) as a string in Haskell?

Have a look at the function runPiped in

   
http://www.pms.informatik.uni-muenchen.de/mitarbeiter/panne/haskell_libs/daVinci/DaVinci.hs

which is part of the daVinci for Haskell:

   
http://www.pms.informatik.uni-muenchen.de/mitarbeiter/panne/haskell_libs/daVinci.html

It connects to an external program and returns (apart from the process
id) two handles for communication: One for reading the stdout from the
other program and another for writing into its stdin. If you only ask
for a simple one-way communication like popen/pclose, simply cut down
runPiped. You can use hGetContents to read from a Handle.

[ AFAIK popen/pclose is not in the POSIX standard, but inclusion in
  GHC's libs would be nice anyway. <= Hint!  :-)  ]

> Also, what are the "handles" mentioned in the ghc Posix library
> and how do they relate to the file descriptors?

Handles are basically Haskell's equivalent of C's FILE*, see

   http://haskell.org/onlinelibrary/io.html

Cheers,
   Sven
-- 
Sven Panne                                        Tel.: +49/89/2178-2235
LMU, Institut fuer Informatik                     FAX : +49/89/2178-2211
LFE Programmier- und Modellierungssprachen              Oettingenstr. 67
mailto:[EMAIL PROTECTED]            D-80538 Muenchen
http://www.pms.informatik.uni-muenchen.de/mitarbeiter/panne

Reply via email to