The Fugue

Counterpoint by Hans Fugal

Filter stderr

Posted by Hans Fugal Tue, 26 Aug 2008 04:19:36 GMT

I've been exploring D the language. I really do like it, but that's another post. There are a couple of D compilers, but the only viable option on OS X seems to be gdc. I installed it via MacPorts. On Leopard, gdc generates assembly that makes the FSF gcc complain "indirect jmp without `*'" over and over. The bug is known, and other than being annoying it seems harmless.

So I decided what I needed was a script that would filter out these frivolous warnings without otherwise affecting stderr, and also without changing the exit status (so make can do the right thing). This turned out to be easier said than done. Finally I stumbled on the right incantation:

#! /bin/bash
gdc=/opt/local/bin/gdc
msg="indirect jmp without"
$gdc "$@" 2> >(grep -v "$msg" 1>&2)

We redirect stderr to the named pipe corresponding to that subshell (see "Process Substitution" in the bash manpage), then we redirect grep's output to its stderr. Because grep is in a subshell, its exit status doesn't mess up the exit status of the script, which is the exit status of gdc, as it should be.

no comments |