且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Python中使用环境变量执行Windows批处理文件?

更新时间:2023-09-10 10:01:28

我想这已经在前一个问题的评论中解决了。 />


当环境变量 HOME_LOCATION 有一个尾部反斜杠时,这可能会失败。



要处理这个 os.path.join 可以用来处理目录分隔符:

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