[Haskell-cafe] hPutStrLn and hFlush
sebastian.sylvan at gmail.com
Mon Jan 9 11:16:00 EST 2006
On 1/9/06, Gracjan Polak <gracjanpolak at gmail.com> wrote:
> Hi all,
> A bit strange behaviour with hPutStrLn. Consider following program:
> main = do
> handle <- openFile "output.txt" WriteMode
> hPutStrLn handle (unlines contLines2)
> -- hFlush houtput
> contLines2 = flip map [1..2000] $
> \x -> show x ++ " been there done that"
> Outputs file which ends with following lines:
> 1989 been there done that
> 1990 been there done that
> 1991 been there done that
> 1992 been there done that
> So the output is truncated. When I uncomment hFlush, file is fully written.
> Is this expected/documented behaviour?
> Platform: WinXP, GHC version 6.4.1
Looks like the buffering is BlockBuffering for your output. Try
changing that using hSetBuffering stdout LineBuffering (or
I believe it gets flushed if you close the file as well...
More information about the Haskell-Cafe