putStr in compiled binary from GHC, Mac OS X

executable, ghc, haskell, io

Solution

You need to use `hSetBuffering` from `System.IO`

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

Problem

With this file: ``` main = do putStr "Input: " s <- getLine putStr s ``` It does what I want in GHCi, which is to put the prompt and then allow input right there on the same line as the prompt. If I compile it and run the executable in the terminal I won't see the prompt until after I do my input. Something about the new lines. I'm using Mac OS 10.8.5, GHC 7.4.2. Is there a terminal setting or GHC option that I need to switch to get the behavior I want from the executable?

Original source