在Mac OS X终端中使用ctrl + D时stdin的信号EOF不起作用 [英] signal EOF of stdin when in mac OS X terminal with ctrl+D doesn't work

查看:320
本文介绍了在Mac OS X终端中使用ctrl + D时stdin的信号EOF不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Mac OS X EL机长,并尝试弄清楚如何发出EOF信号,但是ctrl + D不起作用.我已经在使用stty all的终端上确认eof = ^ D.

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.

在Haskell中使用以下代码

With the following code in Haskell

Module Input where

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


main =
   interact (concat . sort . lines)

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

The expression will never give me any stdout - I have tried ctrl+d , but nothing happens. Why is this?

我在GHCI中运行此程序

推荐答案

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

(Note: Question about running the program in GHCI.)

根据9年前的本TRAC问题,错误.

您可以hSetBuffer stdin LineBuffering并且Control-D将被识别,但是当GHCI返回REPL提示时,GHCI还将引发句柄关闭"错误,并且会话将终止:

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

这篇关于在Mac OS X终端中使用ctrl + D时stdin的信号EOF不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆