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):