From dbe2119ed1764f781c3e33eb57ba410122ee45b0 Mon Sep 17 00:00:00 2001 From: arun3688 Date: Mon, 11 Nov 2024 12:29:23 +0100 Subject: [PATCH] read the bat file to set up the process environment (#229) --- OMPython/__init__.py | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/OMPython/__init__.py b/OMPython/__init__.py index b0a4af9..6e07b04 100755 --- a/OMPython/__init__.py +++ b/OMPython/__init__.py @@ -933,25 +933,18 @@ def _run_cmd(self, cmd: list, verbose: bool = True): if platform.system() == "Windows": omhome = os.path.join(os.environ.get("OPENMODELICAHOME")) - dllPath = (os.path.join(omhome, "bin") - + os.pathsep + os.path.join(omhome, "lib/omc") - + os.pathsep + os.path.join(omhome, "lib/omc/cpp") - + os.pathsep + os.path.join(omhome, "lib/omc/omsicpp")) - - # include path to resources of defined external libraries - for element in self.lmodel: - if element is not None: - if isinstance(element, str): - if element.endswith("package.mo"): - pkgpath = element[:-10] + '/Resources/Library/' - for wver in ['win32', 'win64']: - pkgpath_wver = pkgpath + '/' + wver - if os.path.exists(pkgpath_wver): - dllPath = pkgpath_wver + os.pathsep + dllPath - - # fix backslash in path definitions - dllPath = dllPath.replace("\\", "/") - + dllPath = "" + + ## set the process environment from the generated .bat file in windows which should have all the dependencies + batFilePath = os.path.join(self.tempdir, '{}.{}'.format(self.modelName, "bat")).replace("\\", "/") + if (not os.path.exists(batFilePath)): + print("Error: bat does not exist " + batFilePath) + + with open(batFilePath, 'r') as file: + for line in file: + match = re.match(r"^SET PATH=([^%]*)", line, re.IGNORECASE) + if match: + dllPath = match.group(1).strip(';') # Remove any trailing semicolons my_env = os.environ.copy() my_env["PATH"] = dllPath + os.pathsep + my_env["PATH"] else: