I have a unicode filename that I would like to open.
The following code:
cmd = u'cmd /c "C:\\Pok\xe9mon.mp3"'
cmd = cmd.encode('utf-8')
subprocess.Popen(cmd)
returns
>>> 'C:\Pokיmon.mp3' is not recognized as an internal or external command, operable program or batch file.
even though the file do exist. Why is this happening?
It looks like you’re using Windows and Python 2.X. Use os.startfile:
Non-intuitively, getting the command shell to do the same thing is:
On my system, the command shell (cmd.exe) encoding is
cp437, but for Windows programs iscp1252.Popenwanted shell commands encoded ascp1252. This seems like a bug, and it also seems fixed in Python 3.X: