1. <i id='NUvD9'><tr id='NUvD9'><dt id='NUvD9'><q id='NUvD9'><span id='NUvD9'><b id='NUvD9'><form id='NUvD9'><ins id='NUvD9'></ins><ul id='NUvD9'></ul><sub id='NUvD9'></sub></form><legend id='NUvD9'></legend><bdo id='NUvD9'><pre id='NUvD9'><center id='NUvD9'></center></pre></bdo></b><th id='NUvD9'></th></span></q></dt></tr></i><div id='NUvD9'><tfoot id='NUvD9'></tfoot><dl id='NUvD9'><fieldset id='NUvD9'></fieldset></dl></div>
    2. <small id='NUvD9'></small><noframes id='NUvD9'>

        <legend id='NUvD9'><style id='NUvD9'><dir id='NUvD9'><q id='NUvD9'></q></dir></style></legend>
          <bdo id='NUvD9'></bdo><ul id='NUvD9'></ul>
      1. <tfoot id='NUvD9'></tfoot>

        subprocess.Popen 带有 unicode 路径

        时间:2023-07-21
        <tfoot id='KkEuM'></tfoot>
          • <small id='KkEuM'></small><noframes id='KkEuM'>

            <legend id='KkEuM'><style id='KkEuM'><dir id='KkEuM'><q id='KkEuM'></q></dir></style></legend>
            1. <i id='KkEuM'><tr id='KkEuM'><dt id='KkEuM'><q id='KkEuM'><span id='KkEuM'><b id='KkEuM'><form id='KkEuM'><ins id='KkEuM'></ins><ul id='KkEuM'></ul><sub id='KkEuM'></sub></form><legend id='KkEuM'></legend><bdo id='KkEuM'><pre id='KkEuM'><center id='KkEuM'></center></pre></bdo></b><th id='KkEuM'></th></span></q></dt></tr></i><div id='KkEuM'><tfoot id='KkEuM'></tfoot><dl id='KkEuM'><fieldset id='KkEuM'></fieldset></dl></div>
                <tbody id='KkEuM'></tbody>

              • <bdo id='KkEuM'></bdo><ul id='KkEuM'></ul>

                  本文介绍了subprocess.Popen 带有 unicode 路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想打开一个 unicode 文件名.以下代码:

                  I have a unicode filename that I would like to open. The following code:

                  cmd = u'cmd /c "C:\Pokxe9mon.mp3"'
                  cmd = cmd.encode('utf-8')
                  subprocess.Popen(cmd)
                  

                  返回

                  >>> 'C:Pokmon.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?

                  推荐答案

                  看起来您使用的是 Windows 和 Python 2.X.使用 os.startfile:

                  It looks like you're using Windows and Python 2.X. Use os.startfile:

                  >>> import os
                  >>> os.startfile(u'Pokémon.mp3')
                  

                  不直观地,让命令 shell 做同样的事情是:

                  Non-intuitively, getting the command shell to do the same thing is:

                  >>> import subprocess
                  >>> import locale
                  >>> subprocess.Popen(u'Pokémon.mp3'.encode(locale.getpreferredencoding()),shell=True)
                  

                  在我的系统上,命令 shell (cmd.exe) 编码是 cp437,但对于 Windows 程序是 cp1252.Popen 想要编码为 cp1252 的 shell 命令.这似乎是一个错误,在 Python 3.X 中似乎也已修复:

                  On my system, the command shell (cmd.exe) encoding is cp437, but for Windows programs is cp1252. Popen wanted shell commands encoded as cp1252. This seems like a bug, and it also seems fixed in Python 3.X:

                  >>> import subprocess
                  >>> subprocess.Popen('Pokémon.mp3',shell=True)
                  

                  这篇关于subprocess.Popen 带有 unicode 路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Python os.system 没有输出 下一篇:Python subprocess 模块,我如何为管道命令系列中的第一个提供输入?

                  相关文章

                • <legend id='DF96X'><style id='DF96X'><dir id='DF96X'><q id='DF96X'></q></dir></style></legend>
                • <tfoot id='DF96X'></tfoot>

                  <small id='DF96X'></small><noframes id='DF96X'>

                      • <bdo id='DF96X'></bdo><ul id='DF96X'></ul>
                    1. <i id='DF96X'><tr id='DF96X'><dt id='DF96X'><q id='DF96X'><span id='DF96X'><b id='DF96X'><form id='DF96X'><ins id='DF96X'></ins><ul id='DF96X'></ul><sub id='DF96X'></sub></form><legend id='DF96X'></legend><bdo id='DF96X'><pre id='DF96X'><center id='DF96X'></center></pre></bdo></b><th id='DF96X'></th></span></q></dt></tr></i><div id='DF96X'><tfoot id='DF96X'></tfoot><dl id='DF96X'><fieldset id='DF96X'></fieldset></dl></div>