Python under PowerShell adds characters

eryk sun eryksun at gmail.com
Wed Mar 29 15:59:33 EDT 2017


On Wed, Mar 29, 2017 at 7:13 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
> eryk sun <eryksun at gmail.com>:
>> PowerShell is far more invasive. Instead of giving the child process a
>> handle for the file, it gives it a handle for a *pipe*. PowerShell
>> reads from the pipe, and like an annoying busybody that no asked for,
>> decodes the output as text,
>
> You mean, a bit like Python3 does?

The closest to what we're talking about here would be using
subprocess.Popen and friends to create pipelines and redirect output
to files. Opening a file defaults to text mode in Python for how
Python access the file, but if you pass a file descriptor as Popen's
stdout argument, Python isn't acting as a middle man. The child
process writes directly to the file.

PowerShell makes itself a middle man in the cases of file redirection
and pipelines. It does this to enable all of the capabilities of its
object pipeline. That's fine. But, IMO, there should be a simple way
to get the plain-old redirection and piping in which the shell is not
a middle man. The simplest way I know to do that in PowerShell  is to
run the command line via `cmd /c`. But I'm no PowerShell expert.


More information about the Python-list mailing list