title: How do I use subprocess.Popen to connect multiple processes by pipes?
body: <p>How do I execute the following shell command using the Python <a href="https://docs.python.org/library/subprocess.html" rel="noreferrer"><code>subprocess</code></a> module?</p>
  
  <pre><code>echo "input data" | awk -f script.awk | sort &gt; outfile.txt
  </code></pre>
  
  <p>The input data will come from a string, so I don't actually need <code>echo</code>.  I've got this far, can anyone explain how I get it to pipe through <code>sort</code> too?</p>
  
  <pre><code>p_awk = subprocess.Popen(["awk","-f","script.awk"],
                            stdin=subprocess.PIPE,
                            stdout=file("outfile.txt", "w"))
  p_awk.communicate( "input data" )
  </code></pre>
  
  <p><strong>UPDATE</strong>:  Note that while the accepted answer below doesn't actually answer the question as asked, I believe S.Lott is right and it's better to avoid having to solve that problem in the first place!</p>