问题
I am on a mac OS X EL Captain and try to figure out how to signal EOF , however ctrl + D doesn't work. I have confirmed with the terminal using stty all
that eof = ^D.
With the following code in Haskell
Module Input where
import Data.List
import Data.Char
import System.IO (isEOF)
main =
interact (concat . sort . lines)
The expression will never give me any stdout - I have tried ctrl+d , but nothing happens. Why is this?
I run this program in GHCI
回答1:
(Note: Question about running the program in GHCI.)
According to this TRAC issue from 9 years ago it is not considered a bug.
You can hSetBuffer stdin LineBuffering
and Control-D will be recognized, but GHCI will also raise a "handle is closed" error when it comes back to the REPL prompt and the session will terminate:
$ ghci ./control-d.hs
GHCi, version 7.10.2: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Input ( control-d.hs, interpreted )
Ok, modules loaded: Input.
*Input> import System.IO
*Input System.IO> hSetBuffering stdin LineBuffering
*Input System.IO> :main
jhskdfjhdf
jhskdfjhdf<stdin>: hGetBuffering: illegal operation (handle is closed)
$
来源:https://stackoverflow.com/questions/39216372/signal-eof-of-stdin-when-in-mac-os-x-terminal-with-ctrld-doesnt-work