Hello,<div>this happens because &quot;head&quot; probably closes the file descriptor after 3 lines, and then the Haskell program tries to write to a closed handle (i.e., it&#39;s stdout is not there anymore).  The best thing to do depends on the program. One fairly simple option would be to handle the exception, and do something (perhaps ignore it).</div>
<div>-Iavor</div><div><br><div class="gmail_quote">On Mon, Aug 27, 2012 at 10:55 AM, Eric Tanter <span dir="ltr">&lt;<a href="mailto:etanter@dcc.uchile.cl" target="_blank">etanter@dcc.uchile.cl</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
Here is a simple shell script (upper.hs):<br>
<br>
import Data.Char<br>
main = interact $ map toUpper<br>
<br>
which composes fine with other scripts:<br>
<br>
bash-3.2$ yes | head -n 3 | runghc upper.hs<br>
Y<br>
Y<br>
Y<br>
<br>
but not always:<br>
<br>
bash-3.2$ yes | runghc upper.hs | head -n 3<br>
Y<br>
Y<br>
Y<br>
&lt;stdout&gt;: hFlush: resource vanished (Broken pipe)<br>
<br>
Any idea why this error occurs/how to avoid it?<br>
<br>
(running just:<br>
yes | runghc upper.hs<br>
gives the expected infinite stream of Ys)<br>
<br>
Thanks!<br>
<br>
-- Éric<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br></div>