signal EOF of stdin when in mac OS X terminal with ctrl+D doesn't work

随声附和 提交于 2019-12-12 20:05:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!