<bdo id='2Zt0r'></bdo><ul id='2Zt0r'></ul>
    1. <legend id='2Zt0r'><style id='2Zt0r'><dir id='2Zt0r'><q id='2Zt0r'></q></dir></style></legend>

    2. <small id='2Zt0r'></small><noframes id='2Zt0r'>

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

      1. Python:子进程中的持久外壳变量

        Python: Persistent shell variables in subprocess(Python:子进程中的持久外壳变量)
            • <small id='TKW0I'></small><noframes id='TKW0I'>

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

                  本文介绍了Python:子进程中的持久外壳变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用 Python 的 subprocess 模块执行一系列命令,但是我需要在运行它们之前使用 export 设置 shell 变量.当然,shell 似乎不是持久的,所以当我稍后运行命令时,这些 shell 变量会丢失.

                  I'm trying to execute a series of commands using Pythons subprocess module, however I need to set shell variables with export before running them. Of course the shell doesn't seem to be persistent so when I run a command later those shell variables are lost.

                  有没有办法解决这个问题?我可以创建一个/bin/sh 进程,但是如何获得在该进程下运行的命令的退出代码?

                  Is there any way to go about this? I could create a /bin/sh process, but how would I get the exit codes of the commands run under that?

                  推荐答案

                  subprocess.Popen 采用一个可选的命名参数 env,它是用作子进程环境的字典(你所描述的shell变量").根据需要准备一个字典(您可以从 os.environ 的副本开始并根据需要进行更改)并将其传递给所有 subprocess.Popen 调用您执行.

                  subprocess.Popen takes an optional named argument env that's a dictionary to use as the subprocess's environment (what you're describing as "shell variables"). Prepare a dict as you need it (you may start with a copy of os.environ and alter that as you need) and pass it to all the subprocess.Popen calls you perform.

                  这篇关于Python:子进程中的持久外壳变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)
                  <i id='sqcvO'><tr id='sqcvO'><dt id='sqcvO'><q id='sqcvO'><span id='sqcvO'><b id='sqcvO'><form id='sqcvO'><ins id='sqcvO'></ins><ul id='sqcvO'></ul><sub id='sqcvO'></sub></form><legend id='sqcvO'></legend><bdo id='sqcvO'><pre id='sqcvO'><center id='sqcvO'></center></pre></bdo></b><th id='sqcvO'></th></span></q></dt></tr></i><div id='sqcvO'><tfoot id='sqcvO'></tfoot><dl id='sqcvO'><fieldset id='sqcvO'></fieldset></dl></div>
                1. <legend id='sqcvO'><style id='sqcvO'><dir id='sqcvO'><q id='sqcvO'></q></dir></style></legend>
                    <bdo id='sqcvO'></bdo><ul id='sqcvO'></ul>
                    <tfoot id='sqcvO'></tfoot>

                          <tbody id='sqcvO'></tbody>

                          1. <small id='sqcvO'></small><noframes id='sqcvO'>