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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Bugzilla from alfonso.acosta@gmail.com
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
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

Bugzilla from alfonso.acosta@gmail.com
In case it helps, I have just confirmed the same behaviour under Windows.
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

RE: runCommand/waitForProcess don't respect text printing order whenstdout is redirected

Bayley, Alistair-3
In reply to this post by Bugzilla from alfonso.acosta@gmail.com
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Alfonso Acosta
>
> The following program behaves as expected when run on a terminal.
>
> However, when stdout is redirected to a file, the order is no
> longer respected:


Possibly buffering? I think the terminal has line buffering by default,
whereas files are usually block-buffered. Try changing the buffering to
line:

  hSetBuffering stdout LineBuffering

Alistair
*****************************************************************
Confidentiality Note: The information contained in this message,
and any attachments, may contain confidential and/or privileged
material. It is intended solely for the person(s) or entity to
which it is addressed. Any review, retransmission, dissemination,
or taking of any action in reliance upon this information by
persons or entities other than the intended recipient(s) is
prohibited. If you received this in error, please contact the
sender and delete the material from any computer.
*****************************************************************

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: runCommand/waitForProcess don't respect text printing order whenstdout is redirected

Bugzilla from alfonso.acosta@gmail.com
On Fri, Aug 1, 2008 at 4:25 PM, Bayley, Alistair
<[hidden email]> wrote:
> Possibly buffering? I think the terminal has line buffering by default,
> whereas files are usually block-buffered. Try changing the buffering to
> line:
>
>  hSetBuffering stdout LineBuffering

Thanks! That worked.

Sorry for the noise. I assumend that files, just like terminals, where
line-buffered.
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: runCommand/waitForProcess don't respect text printing order whenstdout is redirected

Johannes Waldmann
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


>>  hSetBuffering stdout LineBuffering

I run into this from time to time as well.
I think the ghc (runtime) runtime behaviour is confusing here,
as it tries to be too clever. I don't think it should
even try to find out whether it's writing to terminal or file.

Best regards, J.W.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iEYEARECAAYFAkiTMRkACgkQDqiTJ5Q4dm8MRACfev267AhVPuxkDtCNP6Wz0G/n
CLMAn1RqRS2qRtlDnnzneF2M9kr2QoiR
=pi+1
-----END PGP SIGNATURE-----
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: runCommand/waitForProcess don't respect text printing order whenstdout is redirected

Henning Thielemann

On Fri, 1 Aug 2008, Johannes Waldmann wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
>
> >>  hSetBuffering stdout LineBuffering
>
> I run into this from time to time as well.
> I think the ghc (runtime) runtime behaviour is confusing here,
> as it tries to be too clever. I don't think it should
> even try to find out whether it's writing to terminal or file.

As far as I know it's the same behaviour as that of C standard libraries.

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries