In Python program we can set system environment variables by using os.environ. For example,
But there is a problem that the variable will be disappear after the Python program exits because the variable is owned by the Python program.
The following way can solve the problem to create an environment variable with Python and share it with other programs.
-Count
The following way can solve the problem to create an environment variable with Python and share it with other programs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python ChgEnv.py %1 | |
call Temp.bat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
File = open ("Temp.bat", "w+") | |
File.write ("set DDD=%s\n" % sys.argv [1]) | |
File.close () |