简体   繁体   English

从python调用bat文件并导入环境

[英]Call a bat file from python and import the environment

I'm writing a python script to coordinate building of a number of Qt-projects on windows. 我正在编写一个Python脚本来协调Windows上多个Qt项目的构建。 The python script decides which architecture to build for, and which versions of Visual Studio and Qt to use. python脚本决定要构建的体系结构以及要使用的Visual Studio和Qt的版本。 After that is done I would like to run the proper qtenv2.bat and vcvarsall.bat to setup my environment, and then import the resulting environment for use in my python file. 完成之后,我想运行正确的qtenv2.bat和vcvarsall.bat来设置我的环境,然后导入生成的环境以在我的python文件中使用。

If the bat files contained only setting of environment variables this would be easy, but since the also contain logic and stuff I need to actually run them and pickup the changes they have done. 如果bat文件仅包含环境变量的设置,这将很容易,但是由于bat文件还包含逻辑和内容,因此我需要实际运行它们并选择所做的更改。

I can solve this by using multiple bat/py scripts, but my goal is to write one python script to take care of this build process. 我可以使用多个bat / py脚本解决此问题,但我的目标是编写一个python脚本来完成此构建过程。

"If the bat files contained only setting of environment variables this would be easy" “如果bat文件仅包含环境变量的设置,这将很容易”

Include a set command at the end of the batch file and capture its output that will be just the listing of the variables in the environment and their values 在批处理文件的末尾包含一个set命令,并捕获其输出,该输出将只是环境中变量及其值的列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM