classification
Title: Make subprocess handling text output with universal_newlines more obious
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.4, Python 3.5
process
Status: closed Resolution: duplicate
Dependencies: Superseder: subprocess.run should alias universal_newlines to text
View: 31756
Assigned To: docs@python Nosy List: Baptiste.Lepilleur, bbayles, docs@python
Priority: normal Keywords:

Created on 2013-02-24 12:20 by Baptiste.Lepilleur, last changed 2018-06-11 13:13 by cheryl.sabella. This issue is now closed.

Messages (3)
msg182872 - (view) Author: Baptiste Lepilleur (Baptiste.Lepilleur) Date: 2013-02-24 12:20
It tooks me a while to figure out that using universal_newlines was the solution to "tell" subprocess that I wanted text string output instead of byte string.

A search on stackoverflow shows that this issue is common and the solution nearly unknown (answer is usually to decode the byte string manually)...

Because dealing with text output is IMHO the most common use case, the subprocess documentation should make it easier to "find" the recipe.

I would suggest changing the documentation so that the universal_newlines is made obvious as it is very important:
1) the first /bin/vikings example be modified to show the use of this flag (at the top of the documentation, most people copy/past that):
  >>> p = subprocess.Popen(args, universal_newlines=True) # Success!
  and at a small comment below the example to explain that flag
2) change other example similarly when that make sense, IMHO:
   - ifconfig example
   - one of the subprocess.check_output example
   - subprocess.check_output() example, consider separating the byte string / text string example for increased visibility
3) consider adding a section with an obvious title "Dealing with binary and text input/output", providing examples and pointer to the correct documentation (I would place it after the convenience functions section for visibility). I think this would help attracting "eye" on this large piece of documentation.
msg223384 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-07-17 22:27
@Baptiste can you provide a patch for this?
msg312868 - (view) Author: bbayles (bbayles) * Date: 2018-02-25 23:19
This is fixed in 3.7 with the `text` parameter. See GitHub PR 4049: https://github.com/python/cpython/pull/4049
History
Date User Action Args
2018-06-11 13:13:21cheryl.sabellasetstatus: open -> closed
superseder: subprocess.run should alias universal_newlines to text
resolution: duplicate
stage: needs patch -> resolved
2018-02-26 15:37:23BreamoreBoysetnosy: - BreamoreBoy
2018-02-25 23:19:08bbaylessetnosy: + bbayles
messages: + msg312868
2014-08-29 21:24:42terry.reedysetstage: needs patch
versions: + Python 3.4, Python 3.5, - Python 3.1, Python 3.2, Python 3.3
2014-07-17 22:27:29BreamoreBoysetnosy: + BreamoreBoy
messages: + msg223384
2013-02-24 12:20:55Baptiste.Lepilleurcreate