Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

debugging .mos script

debugging .mos script

Is there a way to debug .mos scripts / their execution more efficiently?
I'm running them from OMShell, but if there is an error in the script it just says "fail", which is not very helpfull at all.

Just now i had a self defined assert (that i had forgotten about) in the model trigger for one of the parameters, and i was mistakenly looking inside the script itself for the failure ...

Edited by: MSMI - Nov-09-20 16:24:29

Re: debugging .mos script

Call getErrorString() to get messages

Re: debugging .mos script

sjoelund.se wrote:

Call getErrorString() to get messages

I already had getErrorString(); behind every line in the script, it doesnt seem to do much.

Code:

loadFile("model.mo");

getErrorString();
buildModel(model);
getErrorString();
system("model");
getErrorString();

just produces "failed" for me, if the model asserts. Calling it after i get "Failed" also produces nothing.

Edited by: MSMI - Nov-10-20 08:23:45

Re: debugging .mos script

Are you on a Windows OS?
I remember, that the last time I tried system didn't return any output on Windows, at least from mingw shell.

You have to add an output file to get the output of the system command.
See system from the Scripting API.


Similar to system(3). Executes the given command in the system shell.

impure function system
  input String callStr "String to call: sh -c $callStr";
  input String outputFile = "" "The output is redirected to this file (unless already done by callStr)";
  output Integer retval "Return value of the system call; usually 0 on success";
end system;

For your example you probably want to do something like:

Code:

system("./model", "outPutFile.log"); getErrorString();

PS: There is a function to read files called readFile.

Edited by: AnHeuermann - Nov-10-20 13:17:24
There are 0 guests and 0 other users also viewing this topic