How to pass additional arguments by launching flux via command line?

Christian Nörenberg
Christian Nörenberg Altair Community Member
edited July 2022 in Community Q&A

I'm looking for an option to pass additional arguments by launching flux via command line? (Doc link: here)
In python (e.g. with PyCharm) you can pass extra parameters in the "run configurations" and access them with "sys.argv".
I tried to add my own environment variable in the command line, but can't find it / get access in the flux project.

Example 1:

"C:\Altair\2019\flux\Flux\Bin\prg\win64\flux.exe" –application Flux2D –file C:\work\Project_2D.FLU -env MYVAR="asddg"

Here I cant find MYVAR.

Example 2:

"C:\Altair\2019\flux\Flux\Bin\prg\win64\flux.exe" –application Flux2D –file C:\work\Project_2D.FLU "basdsdf"

Here I get an error bc of the unknown argument in the end.

I'm using "subprocess.run()" with "shell=True" to launch the python script (which is almost equal to "os.system()")

Tagged:

Answers

  • Mohammed Elamin_22169
    Mohammed Elamin_22169 New Altair Community Member
    edited May 2022

    Hi Christian, 

    I didn't completely understand your request. what is your purpose of passing env variables through the command line ?.

    if you purpose is to pass some parameters to Flux or get some values out of Flux using python API then you can use set and get command as explained on the document on the link below : 

    https://2022.help.altair.com/2022/flux/Flux/Help/english/UserGuide/English/topics/FluxAPI.htm

    There is also an example files for Python API including on the folder (<Flux_Installation_Directory >\flux\Flux\Api\Python). The Python API have been updated with the recent release of Flux 2022, so it might worth to update to this version. 

    image  

  • Christian Nörenberg
    Christian Nörenberg Altair Community Member
    edited July 2022

    Hi Christian, 

    I didn't completely understand your request. what is your purpose of passing env variables through the command line ?.

    if you purpose is to pass some parameters to Flux or get some values out of Flux using python API then you can use set and get command as explained on the document on the link below : 

    https://2022.help.altair.com/2022/flux/Flux/Help/english/UserGuide/English/topics/FluxAPI.htm

    There is also an example files for Python API including on the folder (<Flux_Installation_Directory >\flux\Flux\Api\Python). The Python API have been updated with the recent release of Flux 2022, so it might worth to update to this version. 

    image  

    Hi Mohammed,

    my intention is to make my path management easier.

    In the script I need to define paths like the model path and settings path.
    At the moment I'm using a settings path like "../../../../settings.json". But it would be much easier to pass the path like with "sys.argv".

    Getting access to the inital command file would be enough for now.
    ("runPy('D:/Work/user/cmd_file.py')"). This should be known in Flux.

  • Christian Nörenberg
    Christian Nörenberg Altair Community Member
    edited July 2022

    I found a solution without using the API:

    Launch flux like this

    "C:\Altair\2019\flux\Flux\Bin\prg\win64\flux.exe" &ndash;application Flux2D &ndash;file C:\work\cmd_file.py -env MY_VAR="asddg"

    To get access to the enviroment variables in flux (while executing the cmd flie):

    #! Flux2D 21.1  import os  var = os.environ['MY_VAR']  # with is "asfda"