python设置执行服务环境变量_如何在Python中使用环境变量执行Windows批处理文件?...

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 ..."

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值