[Haskell-cafe] Unbuffered character IO under Windows XP?

Ryan Ingram ryani.spam at gmail.com
Fri Dec 28 23:14:25 EST 2007


I have this problem as well and would love to hear if there is an answer.

I think there are some windows terminal settings that the GHC runtime should
twiddle when you change the buffering state on stdin, but I don't know
exactly what is involved.

  -- ryan

On 12/28/07, Peter Schmitz <haskell.ps at gmail.com> wrote:
>
> module Main(main) where
> import System.IO
>
> main = do
>    b1 <- hGetBuffering stdin
>    print b1
>    b2 <- hGetBuffering stdout
>    print b2
>
>    -- not sure if these help, or are needed
>    hSetBuffering stdin  NoBuffering
>    hSetBuffering stdout NoBuffering
>
>    b1 <- hGetBuffering stdin
>    print b1
>    b2 <- hGetBuffering stdout
>    print b2
>
>    putStr "0"
>    c <- getChar   -- echoes during input by default
>    putStr "1"     -- want this output w/o hitting Enter
>    hFlush stdout  -- adding this does not help
>    putStrLn [c]
>
> {------------------- Output:
> E:\ghcTest>ghc --version
> The Glorious Glasgow Haskell Compilation System, version 6.8.1
>
> E:\ghcTest>ghc --make main
> [1 of 1] Compiling Main             ( main.hs, main.o )
> Linking main.exe ...
>
> E:\ghcTest>main
> LineBuffering
> LineBuffering
> NoBuffering
> NoBuffering
> 0a
> 1a
>
> E:\ghcTest>
> ----------------- Question:
> Is it possible to have unbuffered character IO under
> Windows XP?
>
> I would like to be able to type a single character and have
> the processing and IO continue without having to hit Enter.
>
> I.e., rather than this
> (had to hit Enter after typing the 'a' in '0a'):
> 0a
> 1a
>
> I would like to have this
> (without having to hit Enter after typing the char):
> 0a1a
>
> I have tried a few combinations of hSetBuffering and
> put/get Str/Char functions, without success.
>
> NOTE:
> I need to run under Windows XP, non-administrator account.
> This test was run using the normal XP shell cmd.exe.
> Thanks much in advance.
> -- Peter
> --------}
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20071228/71324f6e/attachment.htm


More information about the Haskell-Cafe mailing list