runCommand/waitForProcess don't respect text printing order when stdout is redirected

Alfonso Acosta alfonso.acosta at gmail.com
Fri Aug 1 10:13:35 EDT 2008


Hi all,

I'm running ghc 6.8.2 in OSX and Linux.

The following program behaves as expected when run on a terminal.

==
module Main where

import System.Process

main = sequence $ replicate 3 command
 where command = do putStrLn "foo"
                    waitForProcess =<< runCommand "echo echo"
                    putStrLn "bar"
==


$ ghc --make Main.hs -o main
$./main
foo
echo
bar
foo
echo
bar
foo
echo
bar

However, when stdout is redirected to a file, the order is no longer respected:

$ ./main > output
$ cat output
echo
echo
echo
foo
bar
foo
bar
foo
bar

Am I missing something or should I file a bug report?

Thanks in advance,

Fons


More information about the Libraries mailing list