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 main
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). Either: 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@virgin.net>