title: Using groovy, how do you pipe multiple shell commands?
body: <p>Using Groovy and it's <code>java.lang.Process</code> support, how do I pipe multiple shell commands together?</p>
  
  <p>Consider this bash command (and assume your username is <code>foo</code>):</p>
  
  <pre><code>ps aux | grep ' foo' | awk '{print $1}'
  </code></pre>
  
  <p>This will print out usernames - one line for some processes related to your user account.</p>
  
  <p>Using Groovy, the <a href="http://docs.groovy-lang.org/docs/groovy-2.4.5/html/api/org/codehaus/groovy/runtime/ProcessGroovyMethods.html#or(java.lang.Process,%20java.lang.Process)" rel="noreferrer">ProcessGroovyMethods</a> documentation and code says I should be able to do this to achieve the same result:</p>
  
  <pre><code>def p = "ps aux".execute() | "grep ' foo'".execute() | "awk '{print $1}'".execute()
  p.waitFor()
  println p.text
  </code></pre>
  
  <p>However, I can't get any text output for anything other than this:</p>
  
  <pre><code>def p = "ps aux".execute()
  p.waitFor()
  println p.text
  </code></pre>
  
  <p>As soon as I start piping, the println does not print out any anything.</p>
  
  <p>Thoughts?</p>