Hello,
I wanted to pass a variable to a Salome python script, to be more specific, the current location of where I am running the terminal.
but I am not getting the desired behavior.
the python scripts looks like this
import sys
print(sys.argv)
the issue is that if I run it directly from python in the terminal
python3 $scriptPath/scriptTest.py $(pwd)
I get the desired result
['TEST/pythonScript.py', '/mnt/c/Users/Micro/Documents/Testscript']
but when I run it as
cmd.exe /mnt/c/SALOME-9.7.0/run_salome.bat -t $scriptPath/pythonScript.py $(pwd)
the output in the salome python consol is different
['C:\\Users\\Micro\\Documents\\TestScript\\TEST\\pythonScript.py']
I understand the difference in the back and foward slashes from one being the python of windows and the other from ubuntu (WSL). Nevertheless this is not important, but what it matters is that I loss the argument that I am trying to pass to the script.
how can avoid this?
best regards,
F.
Hello,
I face more or less the same problem. I’m running salome_meca2021 on Ubuntu 18.04, and I want to execute a script in a python program:
subprocess.run(run_salome.bat -t -w1 myscript.py, cwd=‘/study_path’)
I’d like to add an argument to my command but I could not find how to do it. I tried
subprocess.run(run_salome.bat -t -w1 myscript.py arg1, cwd=‘/study_path’), but it doesn’t work (I have only the script file as argument).
Anyone knows how to do it?
Best regards,
Jules
I can not remember if I solved, but in my case I was using the salome python script inside a bash script so what i could do was to sed the variable inside the script itself. but can not remember if I solved with a more clean way.
Well, I just found how to do it…
Simply: subprocess.run(run_salome.bat -t -w1 myscript.py args:arg1,arg2…, cwd=‘/study_path’)
1 Like
could I ask 1. what the -w1
flag means and 2. how you use/call arg1
arg2
etc inside the python script?
thanks in advance
-w1 is used to kill the COBRA servers (I use SM2021, and it works in a docker, with it’s own environment). Since I use it in text mode, it’s necessary, else the server will stay open and it will create ‘ghost’ disk.
In my script, I simply do:
import sys
args = sys.argv
You get args = [‘arg1’,‘arg2’…]
1 Like