Python calls bat and pythonbat to set Environment Variables

Source: Internet
Author: User

Python calls bat and pythonbat to set Environment Variables

A python script is used in the work to automatically run multiple vc project codes under a directory.

The commands of the compilation project code are as follows: the direct operation will fail, and the system cannot find devenv. the directory where devenv.exe is located must be added to the environment variable.

OS. system ('devev' + name + '. sln/project' + name + '. vcproj/Rebuild "debug | win32"/out' + name + '. cmp> nul ')

 

The project team has a self-compiled bat script for adding various temporary environment variables, which also contains the vc environment variables. So I want to directly call the existing script in python and then execute the compilation command, but it does not work. It is said that OS. system is an independent process and the modification of environment variables does not take effect for subsequent statements.

OS. system ('call ".../set_vs_env.bat "')
OS. system ('devev' + name + '. sln/project' + name + '. vcproj/Rebuild "debug | win32"/out' + name + '. cmp> nul ')

 

Therefore, only two cmd commands can be executed in one call, that is, multiple cmd commands can be executed at a time, and cmd commands can be connected with the & operator.

Cmd = 'call ".. /.. /set_vs_env.bat "& '+ 'venv' + name + '. sln/project' + name + '. vcproj/Rebuild "debug | win32"/out' + name + '. cmp> nul'
OS. system (cmd)

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.