PutStr in compiled binary format from GHC, Mac OS X

With this file:

main = do
  putStr "Input: "
  s <- getLine
  putStr s

It does what I want in GHCi, which is to put the invitation and then allow input there on the same line as the invitation. If I compile it and run the executable in the terminal, I will not see the invitation until I have made my input. Something about new lines. I am using Mac OS 10.8.5, GHC 7.4.2.

Is there a terminal parameter or a GHC parameter that I need to switch to get the behavior I want from the executable?

+4
source share
2 answers

You need to use hSetBufferingfromSystem.IO

main = do
    hSetBuffering stdout NoBuffering
    putStr "Input: "
    s <- getLine
    putStr s
+7
source

: hFlush stdout, .

, , - .

+1

All Articles