On 29 Aug 2014 17:52, "Paul Moore" <p.f.moore@gmail.com> wrote:
>
> At the moment, subprocess offers two options for handlingthe standard
> IO streams of the child. By default, the streams are binary, or you
> can set universal_newlines to get text-mode streams with universal
> newline handling enabled.
>
> With universal_newlines, the encoding of the streams is the default
> value for the environment (whatever locale.getpreferredencoding()
> returns). However, there can be cases where you want finer control
> over the encoding to use (for example, if you run Python in a
> subprocess and set PYTHONIOENCODING).
>
> I propose adding an "encoding" parameter to subprocess.Popen (and the
> various wrapper routines) to allow specifying the actual encoding to
> use.
>
> Obviously, you can simply wrap the binary streams yourself - the main
> use for this facility would be in the higher level functions like
> check_output and communicate.
>
> Does this seem like a reasonable suggestion?

This actually gets a little messy once you start digging into it, as you actually have up to 3 streams to deal with (stdin, stdout, stderr), and may want to set the error handler in addition to the encoding.

http://bugs.python.org/issue6135 has the many gory details.

It's a problem that definitely needs solving, but it may be better approached by making it easier to create the pipes *separately*, and then pass relevant details into the subprocess call.

As with win_unicode_console (and even contextlib2), it's probably worth experimenting in a PyPI module, as that will make it easier for people to try out with existing Python 3 releases.

Cheers,
Nick.

> Paul
> _______________________________________________
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/