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

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

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

      2. 修改环境的 Python 子进程/Popen

        Python subprocess/Popen with a modified environment(修改环境的 Python 子进程/Popen)

            <tbody id='T027Q'></tbody>

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

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

                  本文介绍了修改环境的 Python 子进程/Popen的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我相信在稍加修改的环境下运行外部命令是很常见的情况.这就是我倾向于这样做的方式:

                  I believe that running an external command with a slightly modified environment is a very common case. That's how I tend to do it:

                  import subprocess, os
                  my_env = os.environ
                  my_env["PATH"] = "/usr/sbin:/sbin:" + my_env["PATH"]
                  subprocess.Popen(my_command, env=my_env)
                  

                  我有一种直觉,认为有更好的方法;看起来还好吗?

                  I've got a gut feeling that there's a better way; does it look alright?

                  推荐答案

                  我觉得os.environ.copy()如果你不打算修改当前的os.environ比较好进程:

                  I think os.environ.copy() is better if you don't intend to modify the os.environ for the current process:

                  import subprocess, os
                  my_env = os.environ.copy()
                  my_env["PATH"] = "/usr/sbin:/sbin:" + my_env["PATH"]
                  subprocess.Popen(my_command, env=my_env)
                  

                  这篇关于修改环境的 Python 子进程/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 画布滚动条?)

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

                          <legend id='33EDi'><style id='33EDi'><dir id='33EDi'><q id='33EDi'></q></dir></style></legend>
                            <tbody id='33EDi'></tbody>
                        1. <small id='33EDi'></small><noframes id='33EDi'>