@@ -687,6 +687,45 @@ def run_model_executable(cmd_run_data: OMCSessionRunData) -> int:
687687
688688 return returncode
689689
690+ @staticmethod
691+ def run_model_executable (cmd_run_data : OMCSessionRunData ) -> int :
692+ """
693+ Run the command defined in cmd_run_data. This class is defined as static method such that there is no need to
694+ keep instances of over classes around.
695+ """
696+
697+ my_env = os .environ .copy ()
698+ if isinstance (cmd_run_data .cmd_library_path , str ):
699+ my_env ["PATH" ] = cmd_run_data .cmd_library_path + os .pathsep + my_env ["PATH" ]
700+
701+ cmdl = cmd_run_data .get_cmd ()
702+
703+ logger .debug ("Run OM command %s in %s" , repr (cmdl ), cmd_run_data .cmd_path )
704+ try :
705+ cmdres = subprocess .run (
706+ cmdl ,
707+ capture_output = True ,
708+ text = True ,
709+ env = my_env ,
710+ cwd = cmd_run_data .cmd_cwd_local ,
711+ timeout = cmd_run_data .cmd_timeout ,
712+ check = True ,
713+ )
714+ stdout = cmdres .stdout .strip ()
715+ stderr = cmdres .stderr .strip ()
716+ returncode = cmdres .returncode
717+
718+ logger .debug ("OM output for command %s:\n %s" , repr (cmdl ), stdout )
719+
720+ if stderr :
721+ raise OMCSessionException (f"Error running model executable { repr (cmdl )} : { stderr } " )
722+ except subprocess .TimeoutExpired as ex :
723+ raise OMCSessionException (f"Timeout running model executable { repr (cmdl )} " ) from ex
724+ except subprocess .CalledProcessError as ex :
725+ raise OMCSessionException (f"Error running model executable { repr (cmdl )} " ) from ex
726+
727+ return returncode
728+
690729 def execute (self , command : str ):
691730 warnings .warn ("This function is depreciated and will be removed in future versions; "
692731 "please use sendExpression() instead" , DeprecationWarning , stacklevel = 2 )
0 commit comments