POpen/createPipe errors

Hal Daume III hdaume@ISI.EDU
Tue, 28 May 2002 16:43:50 -0700 (PDT)


Hi Jens, GHC folk,

I recently ran into a problem with POpen.  I'm using it lots (on the order
of tens of thousands) of times to run a very fast program on small amounts
of data and after a little while, it dies, saying:


Fail: system error
Action: createPipe

this can be reproduced in this program:

import POpen

main = mapM_ (\x -> popenEnvDir "ls" [(x:"*")] Nothing Nothing
Nothing) (['a'..'z'] ++ ['A'..'Z'])



i ran in to a similar problem with reading files wherein i was opening
(and not closing) too many files using readFile and my solution was to
write a function:

readFileCloseBy :: DeeqSeq a => (String -> a) -> FilePath -> IO a
readFileCloseBy f fp =
    do h <- openFile fp ReadMode
       d <- hGetContents h
       let res = f d
       res `deepSeq` hClose h
       res `deepSeq` (return res)

this function opens and reads a file, parses it using the function
provided, deepSeqs the result and closes the file.

could a similar thing be done with popen?

 - Hal

--
Hal Daume III

 "Computer science is no more about computers    | hdaume@isi.edu
  than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume