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

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

      <tfoot id='DlaMM'></tfoot>

      如何从子进程中获取环境?

      时间:2023-07-04
          <tbody id='iJJrw'></tbody>

        • <small id='iJJrw'></small><noframes id='iJJrw'>

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

          1. <tfoot id='iJJrw'></tfoot>
            • <bdo id='iJJrw'></bdo><ul id='iJJrw'></ul>
              1. 本文介绍了如何从子进程中获取环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想通过python程序调用一个进程,但是,这个进程需要一些由另一个进程设置的特定环境变量.如何获取第一个进程环境变量以将它们传递给第二个?

                I want to call a process via a python program, however, this process need some specific environment variables that are set by another process. How can I get the first process environment variables to pass them to the second?

                这是程序的样子:

                import subprocess
                
                subprocess.call(['proc1']) # this set env. variables for proc2
                subprocess.call(['proc2']) # this must have env. variables set by proc1 to work
                

                但是 to 进程不共享相同的环境.请注意,这些程序不是我的(第一个是又大又丑的 .bat 文件,第二个是专有软件)所以我不能修改它们(好吧,我可以从 .bat 中提取我需要的所有东西,但它非常精巧).

                but the to process don't share the same environment. Note that these programs aren't mine (the first is big and ugly .bat file and the second a proprietary soft) so I can't modify them (ok, I can extract all that I need from the .bat but it's very combersome).

                注意:我使用的是 Windows,但我更喜欢跨平台解决方案(但我的问题不会发生在类 Unix 上......)

                N.B.: I am using Windows, but I prefer a cross-platform solution (but my problem wouldn't happen on a Unix-like ...)

                推荐答案

                既然你显然是在 Windows 中,你需要一个 Windows 答案.

                Since you're apparently in Windows, you need a Windows answer.

                创建一个包装批处理文件,例如.run_program.bat",然后运行两个程序:

                Create a wrapper batch file, eg. "run_program.bat", and run both programs:

                @echo off
                call proc1.bat
                proc2
                

                脚本将运行并设置其环境变量.两个脚本都在同一个解释器(cmd.exe 实例)中运行,因此 prog1.bat 设置的变量 在 prog2 执行时设置.

                The script will run and set its environment variables. Both scripts run in the same interpreter (cmd.exe instance), so the variables prog1.bat sets will be set when prog2 is executed.

                不是很漂亮,但它会起作用.

                Not terribly pretty, but it'll work.

                (Unix 人,你可以在 bash 脚本中做同样的事情:source file.sh".)

                (Unix people, you can do the same thing in a bash script: "source file.sh".)

                这篇关于如何从子进程中获取环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:python-dotenv有什么用? 下一篇:Linux 上 Python 中的环境变量

                相关文章

                1. <legend id='ClZ5N'><style id='ClZ5N'><dir id='ClZ5N'><q id='ClZ5N'></q></dir></style></legend>
                  <tfoot id='ClZ5N'></tfoot>

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

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

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