Click here to Skip to main content
15,902,447 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

<pre>
As of now, I did  <pre>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
Posted
Updated 8-Mar-17 6:41am

1 solution

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:
Python
path = os.environ["LOCATION_HOME"]
os.path.join(path, "binaries\\codeplay.exe")
path + " -testroot ..."
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900