Give an argument to an script run from the python console of salome

how can I give an argument to a script that I want to run in salome (python interface inside salome GUI)?
when I run a script from the gui in the console is runned the following command:

exec(compile(open('/pathToScript/', 'rb').read(), '/pathToScript/', 'exec'))

but lets say I want to give a path to it, how can I achieve this?

form the terminal using salome, it would be something like this

salome -t /pathToScript/ arg0

and then in the script itself I would have:

import sys

thanks in advance

If you want to pass arguments to a script you can do this:
salome args:arg0,arg1

Then in the script sys.argv[0] is the name of the script and sys.argv[1:] the rest of the arguments.
See the example attached to create a block with 3 parameters:

salome args:20,50,30 (1010 Octets)

Hello fred,
giving arguments to a script from the terminal wasn’t the issue (I excuse myself if I wasn’t clear enough I my original post).
what I am looking to do is be able to pass arguments when in the GUI we do file/load script…

this will run in the salome python console the following function:
exec(compile(open('/pathToScript/', 'rb').read(), '/pathToScript/', 'exec'))
I wanted to be able to modify this line to be able to give arguments to the

I know that I can give them when running in the terminal (thanks to one of your previous posts actually!) but it is not what I am looking for right now. as I have a script that I select an object in the interface, and want to run it so it export some parts of it and want to give as input the path to where to export.

From the Python Console of SALOME you can pass the arguments like this:
exec(open(“C:\SALOME-9.12.0\”, “rb”).read(), args=(“20”,“30”,“40”))

But if you need to retrieve the selection then it is different.
You probably should try to create a plugin instead and you will be able to create a small GUI to get the needed parameters.

1 Like

thanks for your reply,
for retrive the selection is quite easy (in case you might need it):

import salome
obj0 = salome.IDToObject(


Thanks :slight_smile: to complete this work for GEOM & SMESH