[Haskell-cafe] Simple shell scripts

Brandon Allbery allbery.b at gmail.com
Mon Aug 27 20:11:54 CEST 2012

On Mon, Aug 27, 2012 at 1:55 PM, Eric Tanter <etanter at dcc.uchile.cl> wrote:

> Here is a simple shell script (upper.hs):

"shell script" means a script written in the shell's programming language.
 This is probably best referred to as a Haskell script.

> bash-3.2$ yes | runghc upper.hs | head -n 3
> Y
> Y
> Y
> <stdout>: hFlush: resource vanished (Broken pipe)
> Any idea why this error occurs/how to avoid it?

It's normal, and shells normally ignore it when programs in the middle of a
pipeline die with SIGPIPE.  Problem here is the Haskell runtime is itself
intercepting the SIGPIPE and throwing a verbose Haskell exception.

Possibly the runtime should detect that stdout is a pipe and disable the
usual SIGPIPE handler, or if it must run cleanup stuff then it should not
print anything and it should after cleanup raise(SIGPIPE) on itself with
the default SIGPIPE handler so the shell will react properly.

You might be able to do this yourself with
(System.Posix.Signals.installHandler openEndedPipe Default Nothing).

brandon s allbery                                      allbery.b at gmail.com
wandering unix systems administrator (available)     (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120827/3ef44306/attachment.htm>

More information about the Haskell-Cafe mailing list