From a607eae0ee6b7126c0a35be263c1990001f7a275 Mon Sep 17 00:00:00 2001 From: syntron Date: Sat, 21 Dec 2024 12:04:33 +0100 Subject: [PATCH] [ModelicaSystem._run_cmd] use argument cwd of subprocess.Popen() instead of handling directory change on our own --- OMPython/__init__.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/OMPython/__init__.py b/OMPython/__init__.py index ff9b9c3e4..d3beee001 100644 --- a/OMPython/__init__.py +++ b/OMPython/__init__.py @@ -814,10 +814,9 @@ def _run_cmd(self, cmd: list): # TODO: how to handle path to resources of external libraries for any system not Windows? my_env = None - currentDir = os.getcwd() try: - os.chdir(self.tempdir) - p = subprocess.Popen(cmd, env=my_env, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p = subprocess.Popen(cmd, env=my_env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + cwd=self.tempdir) stdout, stderr = p.communicate() stdout = stdout.decode('ascii').strip() @@ -828,9 +827,7 @@ def _run_cmd(self, cmd: list): logger.info("OM output for command {}:\n{}".format(cmd, stdout)) p.wait() p.terminate() - os.chdir(currentDir) except Exception as e: - os.chdir(currentDir) raise ModelicaSystemError("Exception {} running command {}: {}".format(type(e), cmd, e)) def _check_error(self):