From aa8c118f7fa45199899a6fa4e28e41cade8b95ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sluka?= Date: Sat, 12 Apr 2025 15:49:54 +0200 Subject: [PATCH 1/2] Fix two spaces in simflags causing error --- OMPython/ModelicaSystem.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OMPython/ModelicaSystem.py b/OMPython/ModelicaSystem.py index fae397ea..c60e8be6 100644 --- a/OMPython/ModelicaSystem.py +++ b/OMPython/ModelicaSystem.py @@ -589,7 +589,7 @@ def simulate(self, resultfile=None, simflags=None): # 11 raise Exception(f"Error: Application file path not found: {exe_file}") cmd = exe_file.as_posix() + override + csvinput + r + simflags - cmd = cmd.split(" ") + cmd = [s for s in cmd.split(' ') if s] self._run_cmd(cmd=cmd) self.simulationFlag = True @@ -1018,7 +1018,7 @@ def linearize(self, lintime=None, simflags=None): # 22 raise Exception(f"Error: Application file path not found: {exe_file}") else: cmd = exe_file.as_posix() + linruntime + override + csvinput + simflags - cmd = cmd.split(' ') + cmd = [s for s in cmd.split(' ') if s] self._run_cmd(cmd=cmd) # code to get the matrix and linear inputs, outputs and states From fea686bbcf5e12c7fdab6b08dcce7daa2841d235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sluka?= Date: Sat, 12 Apr 2025 16:02:49 +0200 Subject: [PATCH 2/2] Do not ignore subprocess returncode Otherwise, it could fail silently (e.g. invalid command line option error is only printed to stdout and not stderr). --- OMPython/ModelicaSystem.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/OMPython/ModelicaSystem.py b/OMPython/ModelicaSystem.py index c60e8be6..3e6b549a 100644 --- a/OMPython/ModelicaSystem.py +++ b/OMPython/ModelicaSystem.py @@ -230,8 +230,9 @@ def _run_cmd(self, cmd: list): raise ModelicaSystemError(f"Error running command {cmd}: {stderr}") if self._verbose and stdout: logger.info("OM output for command %s:\n%s", cmd, stdout) - p.wait() - p.terminate() + # check process returncode, some errors don't print to stderr + if p.wait(): + raise ModelicaSystemError(f"Error running command {cmd}: nonzero returncode") except Exception as e: raise ModelicaSystemError(f"Exception {type(e)} running command {cmd}: {e}")