haskell - 在 mac OS X 终端中使用 ctrl+D 时,stdin 的信号 EOF 不起作用

标签 haskell io osx-elcapitan

我使用的是 mac OS X EL Captain,并尝试弄清楚如何发出 EOF 信号,但是 ctrl + D 不起作用。我已使用 stty all 与终端确认 eof = ^D。

在 Haskell 中使用以下代码

Module Input where

import Data.List
import Data.Char
import System.IO (isEOF)


main =
   interact (concat . sort . lines)

该表达式永远不会给我任何标准输出 - 我已经尝试过 ctrl+d ,但没有任何反应。为什么是这样?

我在 GHCI 中运行这个程序

最佳答案

(注意:有关在 GHCI 中运行程序的问题。)

根据this TRAC issue从 9 年前开始,它不被视为错误。

您可以hSetBuffer stdin LineBuffering并且Control-D将被识别,但GHCI在返回到REPL提示符时也会引发“句柄已关闭”错误,并且 session 将终止:

$ 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)
$

关于haskell - 在 mac OS X 终端中使用 ctrl+D 时,stdin 的信号 EOF 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39216372/

相关文章:

Haskell Print Lines 函数

c++ - 是否有良好的 C++ I/O 使用示例

c - 在 Linux 中从 Bio 结构散列数据

c++ - 用 C 和 C++ 最快的输出到文件

haskell - 具有 purescript-bridge 的多态类型

string - 如何使用parsec获取字符串中特定模式的子字符串

haskell - 如何在 Haskell 中对中缀/运算符进行模式匹配?

python - 无法在 OSX El Capitan (opencv3.1.0) 上的 python2.7 中导入 cv2

svg - Safari 9未显示SVG固定选项卡图标

bash - -bash : ant: command not found on mac os x El Capitan