[Haskell] behavioral difference between GHC and GHCi
glynn.clements at virgin.net
Mon Feb 9 00:30:03 EST 2004
S. Alexander Jacobson wrote:
> This code works echos lines properly under GHCi,
> but just sucks in input when running the GHC
> compiled executable.
> import IO
> main= do
> x<-hGetLine stdin
> putStr x
> Am I doing something wrong?
GHCi automatically disables buffering on stdout for its own purposes.
Compiled binaries don't; they should have the same default behaviour
as programs which are written in C (stdin/stdout are line buffered if
they are correspond to a terminal, and fully buffered otherwise;
stderr is always unbuffered).
1. Use putStrLn instead of putStr.
2. Call "hFlush stdout" after each call to putStr.
3. Call "hSetBuffering stdout NoBuffering" before the first call to putStr.
Glynn Clements <glynn.clements at virgin.net>
More information about the Haskell