Skip to content

Commit dbe2119

Browse files
authored
read the bat file to set up the process environment (#229)
1 parent 2001229 commit dbe2119

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

OMPython/__init__.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -933,25 +933,18 @@ def _run_cmd(self, cmd: list, verbose: bool = True):
933933

934934
if platform.system() == "Windows":
935935
omhome = os.path.join(os.environ.get("OPENMODELICAHOME"))
936-
dllPath = (os.path.join(omhome, "bin")
937-
+ os.pathsep + os.path.join(omhome, "lib/omc")
938-
+ os.pathsep + os.path.join(omhome, "lib/omc/cpp")
939-
+ os.pathsep + os.path.join(omhome, "lib/omc/omsicpp"))
940-
941-
# include path to resources of defined external libraries
942-
for element in self.lmodel:
943-
if element is not None:
944-
if isinstance(element, str):
945-
if element.endswith("package.mo"):
946-
pkgpath = element[:-10] + '/Resources/Library/'
947-
for wver in ['win32', 'win64']:
948-
pkgpath_wver = pkgpath + '/' + wver
949-
if os.path.exists(pkgpath_wver):
950-
dllPath = pkgpath_wver + os.pathsep + dllPath
951-
952-
# fix backslash in path definitions
953-
dllPath = dllPath.replace("\\", "/")
954-
936+
dllPath = ""
937+
938+
## set the process environment from the generated .bat file in windows which should have all the dependencies
939+
batFilePath = os.path.join(self.tempdir, '{}.{}'.format(self.modelName, "bat")).replace("\\", "/")
940+
if (not os.path.exists(batFilePath)):
941+
print("Error: bat does not exist " + batFilePath)
942+
943+
with open(batFilePath, 'r') as file:
944+
for line in file:
945+
match = re.match(r"^SET PATH=([^%]*)", line, re.IGNORECASE)
946+
if match:
947+
dllPath = match.group(1).strip(';') # Remove any trailing semicolons
955948
my_env = os.environ.copy()
956949
my_env["PATH"] = dllPath + os.pathsep + my_env["PATH"]
957950
else:

0 commit comments

Comments
 (0)