
fmohamed:
I am just coming to haskell, and I wrote a simple command to get some input from a pdf file
I just wanted the output of the command so I did something like
import System.Process (runInteractiveCommand) import IO (hGetContents)
-- | returns the text of the first page of the pdf at the given path, needs pdftotext getTextOfPdf :: String -> IO String getTextOfPdf pdfPath = do (inp,out,err,pid) <- runInteractiveCommand ("pdftotext -l 1 "+ +pdfPath++" -") return (hGetContents out)
I don't care about error handling, if something goes wrong it is ok to hang or crash, but knowing unix I wondered if this would do the right thing or if it would create a zombi process.
I was about to ask, but then I thought "let's test it", and sure enough the zombi stays there. I tried to even to allocate more than one, wait, I even managed to exhaust the resources of my machine...
So here is what I would have liked to happen: when the pid gets garbage collected it tries to wait for the process, and if that fails the pid stays around longer and will try to wait later.
Wait for the process to terminate, using waitForProcess pid I've a sketch for a nice wrapper for the low level process code here, http://www.cse.unsw.edu.au/~dons/code/newpopen/ Cheers, Don