title: subprocess.Popen() sends awk and grep lines differently than expected
body: <p>On a CentOS 7.2 I have a file called cpuload, which contains the latest CPU load data in the following format:</p>
  <pre><code>last 30 sec:
  average load: 0
  cpu0 total load:     0
  cpu1 total load:     0
  cpu2 total load:     0
  cpu3 total load:     1
  cpu4 total load:     0
  cpu5 total load:     0
  cpu6 total load:     0
  cpu7 total load:     0
  
  last sec:
  average load: 1
  cpu0 total load:     5
  cpu1 total load:     1
  cpu2 total load:     1
  cpu3 total load:     3
  cpu4 total load:     2
  cpu5 total load:     1
  cpu6 total load:     0
  cpu7 total load:     0
  </code></pre>
  <p>I want to get the number after the &quot;average load:&quot; of the &quot;last sec&quot; bit.
  Two cli commands give me that information when I run them as shell commands on the terminal:
  <code>grep 'average load:' cpuload | sed -n 's/.*load: //p' | tail -n1</code>
  and
  <code>awk 'NR &gt; 2 &amp;&amp; /average load:/ {print $3}' cpuload</code></p>
  <p>But when I run them in subprocess.Popen() with Shell=True I only get stderr:</p>
  <p>for:</p>
  <pre><code>import subprocess
  
  cmd = [&quot;grep&quot;, &quot;'average load:'&quot;, &quot;cpuload&quot;, &quot;|&quot;, &quot;sed&quot;, &quot;-n&quot;, &quot;'s/.*load: //p'&quot;, &quot;|&quot;, &quot;tail&quot;, &quot;-n1&quot;]
  test = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell=True)
  test.stderr.read()
  </code></pre>
  <p>I get:</p>
  <pre><code>b&quot;Usage: grep [OPTION]... PATTERN [FILE]...\nTry 'grep --help' for more information.\n&quot;
  </code></pre>
  <p>and for:</p>
  <pre><code>import subprocess
      
  cmd = cmd = [&quot;awk&quot;, &quot;'NR &gt; 2 &amp;&amp; /average load:/ {print $3}'&quot;, &quot;cpuload&quot;]
  test = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
  test.stderr.read()
  </code></pre>
  <p>I also get:</p>
  <pre><code>b&quot;awk: cmd. line:1: 'NR &gt; 2 &amp;&amp; /average load:/ {print $3}'\nawk: cmd. line:1: ^ invalid char ''' in expression\n&quot;
  </code></pre>
  <p>Even though I avoided using a |</p>
  <p>or if <code>shell=True</code> I get:</p>
  <pre><code>b&quot;Usage: awk [POSIX or GNU style options] -f progfile [--] file ...\nUsage: awk [POSIX or GNU style options] [--] 'program' file ...\nPOSIX options:\t\tGNU long options: (standard)\n\t-f progfile\t\t--file=progfile\n\t-F fs\t\t\t--field-separator=fs\n\t-v var=val\t\t--assign=var=val\nShort options:\t\tGNU long options: (extensions)\n\t-b\t\t\t--characters-as-bytes\n\t-c\t\t\t--traditional\n\t-C\t\t\t--copyright\n\t-d[file]\t\t--dump-variables[=file]\n\t-e 'program-text'\t--source='program-text'\n\t-E file\t\t\t--exec=file\n\t-g\t\t\t--gen-pot\n\t-h\t\t\t--help\n\t-L [fatal]\t\t--lint[=fatal]\n\t-n\t\t\t--non-decimal-data\n\t-N\t\t\t--use-lc-numeric\n\t-O\t\t\t--optimize\n\t-p[file]\t\t--profile[=file]\n\t-P\t\t\t--posix\n\t-r\t\t\t--re-interval\n\t-S\t\t\t--sandbox\n\t-t\t\t\t--lint-old\n\t-V\t\t\t--version\n\nTo report bugs, see node `Bugs' in `gawk.info', which is\nsection `Reporting Problems and Bugs' in the printed version.\n\ngawk is a pattern scanning and processing language.\nBy default it reads standard input and writes standard output.\n\nExamples:\n\tgawk '{ sum += $1 }; END { print sum }' file\n\tgawk -F: '{ print $1 }' /etc/passwd\n&quot;
  </code></pre>
  <p>What am I doing wrong?</p>