Some Python subprocess.Popen tips

subprocess.Popen non-blocking pipe I/O using an additional thread and an asynchronous queue:

Why subprocess.Popen fails on Windows with a command having a Unicode filename within it: it internally uses CreateProcessA, which is the single-byte character version of CreateProcess, meaning that it won’t handle Unicode characters correctly. For this to be correctly handled, the command line, and hence the filename contained, needs to be encoded with the file system encoding, that is usually MBCS.
This thread and the pep below describe exactly this problem as well as the workaround above mentioned.

You will need to specify the encoding of the Python file if you use Unicode characters there: most simply add # encoding=utf-8 as the first or the second line of your source code although there are some more degrees of freedom, which can be found here.

Some Python subprocess.Popen tips

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s