[Haskell-cafe] file descriptors and handles
Brandon S. Allbery KF8NH
allbery at ece.cmu.edu
Mon Mar 8 21:10:45 EST 2010
On Mar 8, 2010, at 14:26 , Mathijs Kwik wrote:
> it writes to the stdIn handle and closes it afterwards.
> - doesn't it need to close the fd as well?
Once you've made a Handle from it, the Handle "owns" it; in
particular, when the Handle is finalized it will close the fd. Also,
attempting to use the fd for anything directly is likely to cause
severe confusion to the process or file on the other end.
> the stdOut handle gets used when reading the command output (using
> - doesn't the handle need to get closed? or will this happen
> automatically if hGetContents finds EOF ?
hGetContents automatically closes the Handle lazily.
> Will reading further output throw an exception or just think it's EOF?
> And what happens when closing the underlying FD? will the handle
> "break"? or will it close automatically?
If you manually close the fd, the Handle will become unhappy and throw
an exception. Don't touch an fd after performing an fdToHandle, or a
Handle after performing a handleToFd (unless you are very certain
about what you're doing, which is likely to require knowledge of how
the GHC runtime's Handles work).
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university KF8NH
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 195 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20100308/c9b23fd3/PGP.bin
More information about the Haskell-Cafe