简体   繁体   中英

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. The python script decides which architecture to build for, and which versions of Visual Studio and Qt to use. 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.

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.

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.

"If the bat files contained only setting of environment variables this would be easy"

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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