[Haskell-cafe] Help with terminal IO

Jason Dagit dagit at codersbase.com
Tue May 29 21:20:57 EDT 2007


On 5/27/07, Ryan Ingram <ryani.spam at gmail.com> wrote:
> I was hoping that hSetBuffering would turn off the line buffering for stdin,
> but it doesn't seem to work.
>
> ----
> module Main where
> import System.IO
>
> main :: IO ()
> main = do
>     hSetBuffering stdin NoBuffering
>     hSetBuffering stdout NoBuffering
>
>     hPutChar stdout '>'
>     c <- hGetChar stdin
>     hPutChar stdout '<'
> ----
>
> This program should terminate immediately after the first character is typed
> into the terminal, but it waits until I type a newline.  It also looks like
> it's using GNU readline (it handles the up & down arrow keys.)
>
> How do I turn this off and use raw character-based IO?  I'm using GHC6.6 on
> Win32 if that makes a difference.

Using the same platform but I get essentially the same behavior.  I
too have to type enter to get the program to accept the input, but
then it exits immediately so I don't know how you tested the up and
down arrows.

When I compile this on debian it works as you expected.  Perhaps this
is a windows bug?

Jason


More information about the Haskell-Cafe mailing list