Opened 5 years ago
Last modified 5 years ago
#5891 reopened defect
getEnvironmentVariable does not return any output
Reported by: | Owned by: | somebody | |
---|---|---|---|
Priority: | normal | Milestone: | 2.0.0 |
Component: | Scripts | Version: | v1.16.0-dev |
Keywords: | Cc: |
Description
Trying in
(str, b) := Modelica.Utilities.System.getEnvironmentVariable("Path", false);
but it returns no output at all, not even with getErrorString()
.
I also tried running on OMSheel and also from command prompt the attached MOS script:
loadModel(Modelica); (str, b) := Modelica.Utilities.System.getEnvironmentVariable("Path"); getErrorString();
that returned.
C:\workspace\_modelica_temp>omc getEnv.mos true Error processing file: getEnv.mos # Error encountered! Exiting... # Please check the error message and the flags. Execution failed!
On Dymola2020, same command returns the expected values.
Am I missing something?
Change History (9)
comment:1 by , 5 years ago
comment:2 by , 5 years ago
On a side note, you don't need to call the MSL function, we have our own in the OpenModelica scripting:
Running this in the script:
getEnvironmentVar("Path"); getErrorString();
will give you what you want.
https://build.openmodelica.org/Documentation/OpenModelica.Scripting.getEnvironmentVar.html
comment:3 by , 5 years ago
Thanks adrpo,
I know that there is an OpenModelica-specific function for this, but I wanted to have a script that could work seemlessly on different compilers and this is the only way.
Thanks again for the effort!
comment:4 by , 5 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
comment:5 by , 5 years ago
Resolution: | worksforme |
---|---|
Status: | closed → reopened |
We should not close this one, we should support it in the compiler via constant evaluation as we do with table functions and other stuff as well.
comment:7 by , 5 years ago
Sorry to bother again, but something strange happens:
I run the MOS script getEnv.mos
loadModel(Modelica); (str1, stat1) := Modelica.Utilities.System.getEnvironmentVariable("Path"); getErrorString(); print("getEnv1: "+str1); getErrorString(); (str2, stat2) := Modelica.Utilities.System.getEnvironmentVariable("Path"); getErrorString(); print("getEnv2: "+str2); getErrorString();
by running from OMEdit>Tools>OpenModelica Command Prompt
the command omc -d=gen getEnv.mos
after having called SET MODELICAUSERCFLAGS=-lOpenModelicaCompiler
However, it seems that only the first getEnvironmentVariable
command works, the second fails.
Here is my output
C:\workspace\_modelica_temp>SET MODELICAUSERCFLAGS=-lOpenModelicaCompiler C:\workspace\_modelica_temp>omc -d=gen getEnv.mos true "" getEnv1: C:\Program Files\OpenModelica\\bin;C:\Program Files\OpenModelica\\lib;C:\Program Files\OpenModelica\\tools\msys\mingw64\bin;C:\Program Files\OpenModelica\\tools\msys\mingw64\lib\gcc\x86_64-w64-mingw32\5.3.0;C:\Program Files\OpenModelica\\tools\msys\usr\bin;C:\workspace\_modelica_temp;C:\workspace\_modelica_temp\..\..\usr\bin\;C:/Program Files/OpenModelica/\bin;C:/Program Files/OpenModelica/\lib\omc\msvc;C:/Program Files/OpenModelica/\lib\omc\cpp;C:/Program Files/OpenModelica/\lib\omc\cpp\msvc; "" Error processing file: getEnv.mos # Error encountered! Exiting... # Please check the error message and the flags. Execution failed!
Do you see any error in my code here?
comment:8 by , 5 years ago
No, and in fact I get the same strange behaviour.
@adrpo, any idea why this happens?
OpenModelica needs to be able to evaluate functions via generating a dll if they are external functions. For that you need
-d=gen
. I guess we should support these functions by default via some constant evaluations in the compiler but we only do it for some of them.Using getEnv.mos:
and
omc -d=gen
you get:It seems there is a bug with the linking and you need to do:
before running
omc -d=gen getEnv.mos
as otherwise the dll will be missingomc_assert
.We should also improve the error message, tell that we cannot evaluate the external function if
-d=gen
is not given.