behavioral difference between GHC and GHCi
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? -Alex- _________________________________________________________________ S. Alexander Jacobson mailto:me@alexjacobson.com tel:917-770-6565 http://alexjacobson.com
You're not really doing anything wrong. You're just another victim of line buffering. Try this, import IO main = do hSetBuffering stdout LineBuffering main2 main2 = do x<-hGetLine stdin putStrLn x main2 On Mon, 09 Feb 2004 11:06 am, 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?
-Alex-
_________________________________________________________________ S. Alexander Jacobson mailto:me@alexjacobson.com tel:917-770-6565 http://alexjacobson.com _______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
-- Why be a man when you can be a success? -- Bertolt Brecht
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>
participants (3)
-
Glynn Clements -
S. Alexander Jacobson -
Thomas L. Bevan