Opened 5 years ago

Last modified 5 years ago

#5891 reopened defect

getEnvironmentVariable does not return any output

Reported by: dariomangoni@… 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 Adrian Pop, 5 years ago

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:

loadModel(Modelica); getErrorString();
(str, b) := Modelica.Utilities.System.getEnvironmentVariable("Path"); getErrorString();
str;
b;

and omc -d=gen you get:

adrpo33@ida-0030 MINGW64 /c/home/adrpo33/dev/OMTesting/bugs/5891
$ ~/dev/OpenModelica/build/bin/omc -d=gen getEnv.mos
true
""

""
"c:\\home\\adrpo33\\dev\\OpenModelica\\build\\bin;c:\\home\\adrpo33\\dev\\OpenModelica\\build\\lib;C:\\OMDev\\tools\\msys\\mingw64\\bin;C:\\OMDev\\tools\\msys\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\5.3.0;C:\\OMDev\\tools\\msys\\usr\\bin;C:\\OMDev\\tools\\msys\\mingw64\\bin;C:\\OMDev\\tools\\msys\\usr\\local\\bin;C:\\OMDev\\tools\\msys\\usr\\bin;C:\\OMDev\\tools\\msys\\usr\\bin;C:\\Windows\\System32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\OMDev\\tools\\msys\\usr\\bin\\site_perl;C:\\OMDev\\tools\\msys\\usr\\bin\\vendor_perl;C:\\OMDev\\tools\\msys\\usr\\bin\\core_perl;C:\\bin\\git\\bin\\;C:\\bin\\jdk\\bin;C:\\Program Files\\TortoiseSVN\\bin"
true

It seems there is a bug with the linking and you need to do:

export MODELICAUSERCFLAGS=-lOpenModelicaCompiler

before running omc -d=gen getEnv.mos as otherwise the dll will be missing omc_assert.

We should also improve the error message, tell that we cannot evaluate the external function if -d=gen is not given.

comment:2 by Adrian Pop, 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 dariomangoni@…, 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 Francesco Casella, 5 years ago

Resolution: worksforme
Status: newclosed

comment:5 by Adrian Pop, 5 years ago

Resolution: worksforme
Status: closedreopened

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:6 by Francesco Casella, 5 years ago

Milestone: Future2.0.0

OK, I tentatively scheduled it for 2.0.0

comment:7 by dariomangoni@…, 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 Francesco Casella, 5 years ago

No, and in fact I get the same strange behaviour.

@adrpo, any idea why this happens?

comment:9 by Martin Sjölund, 5 years ago

comment:7 works fine on Linux

Note: See TracTickets for help on using tickets.