Hi,
I am working on a python code and require to open an executable which is located in my C drive. I dont want to code something like,
file = open("C:\\Documents\\CodeRepo...\\codeplay.exe)
I want to use the environment variable called LOCATION_HOME to point to this exe location.
I dont know when do i set this environment variable. Do i set it in my python code or using the terminal in Windows?
I am still having some issues.
The thing is I provide some extra things in the Popen like shown below.
output = subprocess.Popen(('path -testroot C:\\....\Configuration -projectfile ProjectFilewithTags -environment'
), stdout=subprocess.PIPE).stdout
What I have tried:
As of now, I did
path = os.environ["LOCATION_HOME"]
path += "\\binaries\\codeplay.exe" + "-testroot C:\\....\Configuration -projectfile ProjectFilewithTags -environment".
I PRINT OUT THE PATH IN PYTHON AND IT LOOKS CORRECT. but when I do the opening of the file in the output = .... the system cannot find the file.
output = subprocess.Popen((path
), stdout=subprocess.PIPE).stdout
解决方案I guess this has been already solved within the comments of the previous question.
This might fail when the environment variable HOME_LOCATION has a trailing backslash.
To handle this os.path.join can be used which takes care of the directory separators:
path = os.environ["LOCATION_HOME"]
os.path.join(path, "binaries\\codeplay.exe")
path + "-testroot ..."