title: awk from Python: wrong subprocess arguments?
body: <p>I need to run the following (working) <strong>command</strong> in <strong>Python</strong>:</p>
  
  <pre><code>ip route list dev eth0 | awk ' /^default/ {print $3}'
  </code></pre>
  
  <p>Using <code>subprocess</code>, I would have to do the following:</p>
  
  <pre><code>first = "ip route list dev eth0"
  second = "awk ' /^default/ {print $3}'"
  p1 = subprocess.Popen(first.split(), stdout=subprocess.PIPE)
  p2 = subprocess.Popen(second.split(), stdin=p1.stdout, stdout=subprocess.PIPE)
  p1.stdout.close()  # Allow p1 to receive a SIGPIPE if p2 exits.
  output = p2.communicate()[0]
  </code></pre>
  
  <p>Something went wrong with <code>p2</code>. I get:</p>
  
  <pre><code>&gt;&gt;&gt; awk: cmd. line:1: '
  awk: cmd. line:1: ^ invalid char ''' in expression
  </code></pre>
  
  <p>What should I do? On a terminal it works perfectly.</p>