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

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

        <legend id='KcPlO'><style id='KcPlO'><dir id='KcPlO'><q id='KcPlO'></q></dir></style></legend>

        如何为 popen 指定工作目录

        How can I specify working directory for popen(如何为 popen 指定工作目录)

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

              • <tfoot id='D4nCB'></tfoot>
                • <small id='D4nCB'></small><noframes id='D4nCB'>

                  本文介绍了如何为 popen 指定工作目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有没有办法在Python的subprocess.Popen()中指定命令的运行目录?

                  Is there a way to specify the running directory of command in Python's subprocess.Popen()?

                  例如:

                  Popen('c:mytool	ool.exe', workingdir='d:	estlocal')
                  

                  我的 Python 脚本位于 C:programspython

                  My Python script is located in C:programspython

                  是否可以在D: estlocal目录下运行C:mytool ool.exe?

                  Is is possible to run C:mytool ool.exe in the directory D: estlocal?

                  如何设置子进程的工作目录?

                  How do I set the working directory for a sub-process?

                  推荐答案

                  subprocess.Popen 采用 cwd 参数 来设置当前工作目录;您还需要转义反斜杠 ('d:\test\local'),或使用 r'd: estlocal' 以便Python 不会将反斜杠解释为转义序列.按照您编写的方式, 部分将被转换为 tab.

                  subprocess.Popen takes a cwd argument to set the Current Working Directory; you'll also want to escape your backslashes ('d:\test\local'), or use r'd: estlocal' so that the backslashes aren't interpreted as escape sequences by Python. The way you have it written, the part will be translated to a tab.

                  所以,你的新行应该是这样的:

                  So, your new line should look like:

                  subprocess.Popen(r'c:mytool	ool.exe', cwd=r'd:	estlocal')
                  

                  <小时>

                  要将 Python 脚本路径用作 cwd,import os 并使用以下命令定义 cwd:


                  To use your Python script path as cwd, import os and define cwd using this:

                  os.path.dirname(os.path.realpath(__file__)) 
                  

                  这篇关于如何为 popen 指定工作目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Pythonic and efficient way of finding adjacent cells in grid(在网格中查找相邻单元格的 Pythonic 和有效方法)
                  map a hexagonal grid in matplotlib(在 matplotlib 中映射六边形网格)
                  Execute arbitrary python code remotely - can it be done?(远程执行任意 python 代码 - 可以吗?)
                  Python - Plotting colored grid based on values(Python - 根据值绘制彩色网格)
                  Is there a GUI design app for the Tkinter / grid geometry?(是否有 Tkinter/网格几何图形的 GUI 设计应用程序?)
                  tkinter Canvas Scrollbar with Grid?(带有网格的 tkinter 画布滚动条?)

                      <tbody id='EHEFo'></tbody>

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

                        <legend id='EHEFo'><style id='EHEFo'><dir id='EHEFo'><q id='EHEFo'></q></dir></style></legend>
                      1. <small id='EHEFo'></small><noframes id='EHEFo'>

                          <bdo id='EHEFo'></bdo><ul id='EHEFo'></ul>