title: How to fix an encoding migrating Python subprocess to unicode_literals?
body: <p>We're preparing to move to Python 3.4 and added unicode_literals. Our code relies extensively on piping to/from external utilities using subprocess module. The following code snippet works fine on Python 2.7 to pipe UTF-8 strings to a sub-process:</p>
  
  <pre><code>kw = {}
  kw[u'stdin'] = subprocess.PIPE
  kw[u'stdout'] = subprocess.PIPE
  kw[u'stderr'] = subprocess.PIPE
  kw[u'executable'] = u'/path/to/binary/utility'
  args = [u'', u'-l', u'nl']
  
  line = u'¡Basta Ya!'
  
  popen = subprocess.Popen(args,**kw)
  popen.stdin.write('%s\n' % line.encode(u'utf-8'))
  ...blah blah...
  </code></pre>
  
  <p>The following changes throw this error:</p>
  
  <pre><code>from __future__ import unicode_literals
  
  kw = {}
  kw[u'stdin'] = subprocess.PIPE
  kw[u'stdout'] = subprocess.PIPE
  kw[u'stderr'] = subprocess.PIPE
  kw[u'executable'] = u'/path/to/binary/utility'
  args = [u'', u'-l', u'nl']
  
  line = u'¡Basta Ya!'
  
  popen = subprocess.Popen(args,**kw)
  popen.stdin.write('%s\n' % line.encode(u'utf-8'))
  Traceback (most recent call last):
    File "test.py", line 138, in &lt;module&gt;
      exitcode = main()
    File "test.py", line 57, in main
      popen.stdin.write('%s\n' % line.encode('utf-8'))
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal not in range(128)
  </code></pre>
  
  <p>Any suggestions to pass UTF-8 through the pipe?</p>