[Haskell-cafe] hPutStrLn and hFlush

Sebastian Sylvan 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
>     where
>         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
> 199
> (END)
>
> 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
NoBuffering).

I believe it gets flushed if you close the file as well...

/S


--
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862


More information about the Haskell-Cafe mailing list