title: Is there an easy way to filter stderr in a gradle Exec task?
body: <p>I have an Exec task that runs a command (Inkscape, in "no-gui" mode). This command is incredibly noisy, and tends to spew out a lot of unimportant warnings to stderr. Some of the things it sends to stderr are useful, however, so I don't want to completely suppress its stderr.</p>
  
  <p>Currently I have a wrapper shell script that uses <code>grep -v</code> to filter out messages from stderr that I know are pointless. I then have my Exec task invoke this script.</p>
  
  <p>I'm wondering if there's a way to make this more self-contained, though, so that I don't need to rely on an external shell script.</p>
  
  <hr>
  
  <p>My gradle task looks something like this:</p>
  
  <pre class="lang-groovy prettyprint-override"><code>task createIcon(type:Exec) {
      def outdir = new File(fromSvgDir, "drawable-ldpi/")
      outputs.dir(outdir)
      doFirst {
          outdir.mkdirs()
      }
      def svg = 'src/images/ic_launcher.svg'
      inputs.source(new File(svg))
      def png = new File(outdir, "ic_launcher.png")
      outputs.file(png)
      commandLine "$workingDir/svgToPng.sh", svg, png
  }
  </code></pre>
  
  <p>and <code>svgToPng.sh</code> looks like this:</p>
  
  <pre class="lang-bash prettyprint-override"><code>#!/bin/bash
  svg="$1"
  png="$2"
  
  exec inkscape -z -D -w 48 -e "$png" "$svg" 2&gt; &gt;(
      grep -v '^\*\* (inkscape:[0-9]*): CRITICAL \*\*: dbus_g_' |
      grep -v '^$' |
      grep -v '^Failed to get connection$' &gt;&amp;2
  )
  </code></pre>
  
  <p>(Yes, believe it or not, those "CRITICAL" errors are inconsequential, and Inkscape actually succeeds in doing what it's supposed to do despite them.)</p>