Some Python subprocess.Popen tips

subprocess.Popen non-blocking pipe I/O using an additional thread and an asynchronous queue:
http://stackoverflow.com/questions/3076542/how-can-i-read-all-availably-data-from-subprocess-popen-stdout-non-blocking/3078292#3078292

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.
http://stackoverflow.com/questions/1910275/unicode-filenames-on-windows-with-python-subprocess-popen/9113914#9113914
This thread and the pep below describe exactly this problem as well as the workaround above mentioned.
http://stackoverflow.com/questions/2595448/unicode-filename-to-python-subprocess-call/11442604#11442604
http://www.python.org/dev/peps/pep-0277/

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.
http://www.python.org/dev/peps/pep-0263/

Some Python subprocess.Popen tips

Leave a comment