OpenModelica / OpenModelica

OpenModelica is an open-source Modelica-based modeling and simulation environment intended for industrial and academic usage.
https://openmodelica.org
Other
848 stars 306 forks source link

Add flags to allow piping of Modelica Shell commends into 'omc' #10040

Open jdpipe opened 1 year ago

jdpipe commented 1 year ago

Currently omc can only run .mos scripts by creating a file and then passing the filename, eg omc Script.mos.

It would be helpful if, instead, we could pipe a file (or text) or pass commands directly from the command line, eg

omc --script -e "installPackage(Modelica)"

or

echo "installPackage(Modelica)" | omc --script -

I note that a --script flag would be needed to differentiate between a model (.mo) and script (.mos) content being piped from the command line. It would be useful to be able to handle piped models too, I suppose, but scripting was the primary use case.

This would be convenient in automating the setup of new systems, and for accessing the package manager from bash, and in non-GUI systems such as on supercomputers. In our particular set-up (SolarTherm) we interact with OpenModelica only directly via the omc executable, because we have a workflow involving other tools for pre and post processing; we don't use OMShell or OMEdit except during development/debugging.

I am using OpenModelica 1.20.x.

casella commented 1 year ago

@mahge this is a nice suggestion from our Australian colleagues working in solar power research. They extensively rely on their own CI, and having this functionality simplifies things a lot.

Can you take care of that when you have some time?

Thanks!

jdpipe commented 1 year ago

Thanks Francesco! Obviously I can work around this eg using tempfile.NamedTemporaryFile in Python, but it's clunky. More serious is the lack of basic error reporting from omc here, see #10043. For now I test for text output true, but that might be problematic for other actions.