diff --git a/OMPython/__init__.py b/OMPython/__init__.py index d78b4d1..bbc77c3 100644 --- a/OMPython/__init__.py +++ b/OMPython/__init__.py @@ -947,25 +947,18 @@ def _run_cmd(self, cmd: list): 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: