Ticket #1268 (closed bug: invalid)

Opened 6 years ago

Last modified 6 years ago

GHCi reads from stdin do not handle ^D

Reported by: Stefan O'Rear <stefanor@…> Owned by:
Priority: normal Milestone: 6.8.1
Component: GHCi Version: 6.7
Keywords: Cc: greenrd@…
Operating System: Linux Architecture: x86
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

stefan@stefans:/tmp$ ghc --interactive
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.7.20070402, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base ... linking ... done.
Prelude> getChar
^D'\EOT'
Prelude> getLine
foo^Dbar
"foo\EOTbar"
Prelude> Leaving GHCi.
stefan@stefans:/tmp$ ghc -e 'getChar' -v0
*** Exception: <stdin>: hGetChar: end of file
stefan@stefans:/tmp$ ghc -e 'getLine' -v0
foobar
"foobar"
stefan@stefans:/tmp$

In the first case I pressed C-d immediately after getChar began waiting, in the second case I pressed it in the middle of the word. In both cases the non-interactive output is that which was expected.

The undesirable GHCi output is confirmed with 6.7.20070402, 6.6, and 6.4.2.

Change History

Changed 6 years ago by igloo

  • component changed from Compiler to GHCi
  • milestone set to 6.8

Thanks for the report, we'll look into it for 6.8.

Changed 6 years ago by greenrd

  • cc greenrd@… added

Changed 6 years ago by simonmar

  • status changed from new to closed
  • resolution set to invalid

I claim this is not a bug. GHCi defaults to no buffering on stdin, whereas when running from the command line you get either line-buffering or block-buffering depending on what stdin is attached to. If you want line-buffering in GHCi, you can ask for it:

Prelude> :m + System.IO
Prelude System.IO> hSetBuffering stdin LineBuffering
Prelude System.IO> getChar
*** Exception: <stdin>: hGetChar: end of file
Prelude System.IO> Leaving GHCi.

Perhaps you're complaining about the fact that NoBuffering implies ICANON on Unix ttys, and hence disables the ^D processing. GHC has always had this behaviour, as far as I recall.

Changed 6 years ago by igloo

  • milestone changed from 6.8 branch to 6.8.1
Note: See TracTickets for help on using tickets.