Skip to content

Commit a607eae

Browse files
committed
[ModelicaSystem._run_cmd] use argument cwd of subprocess.Popen() instead of handling directory change on our own
1 parent 2f1f3b4 commit a607eae

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

OMPython/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -814,10 +814,9 @@ def _run_cmd(self, cmd: list):
814814
# TODO: how to handle path to resources of external libraries for any system not Windows?
815815
my_env = None
816816

817-
currentDir = os.getcwd()
818817
try:
819-
os.chdir(self.tempdir)
820-
p = subprocess.Popen(cmd, env=my_env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
818+
p = subprocess.Popen(cmd, env=my_env, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
819+
cwd=self.tempdir)
821820
stdout, stderr = p.communicate()
822821

823822
stdout = stdout.decode('ascii').strip()
@@ -828,9 +827,7 @@ def _run_cmd(self, cmd: list):
828827
logger.info("OM output for command {}:\n{}".format(cmd, stdout))
829828
p.wait()
830829
p.terminate()
831-
os.chdir(currentDir)
832830
except Exception as e:
833-
os.chdir(currentDir)
834831
raise ModelicaSystemError("Exception {} running command {}: {}".format(type(e), cmd, e))
835832

836833
def _check_error(self):

0 commit comments

Comments
 (0)