Execute python scripts without opening 3D-slicer GUI

Hi all,
I have scripted a python code which segments skull from the input DICOM data. When I try to execute the script from CLI using the following command

Slicer.exe --python-script "app.py" --no-splash --no-main-window

the 3d-slicer GUI keeps opening. I need to execute the script without opening GUI.

Thanks in advance. Anyone please help me with it

Does the full Slicer GUI appear? What Slicer version are you using? Does it do the same if you specify full path for Slicer.exe and app.py?

I have scripted a python code which segments skull from the input DICOM data. When I try to execute the script from CLI using the following command

Slicer.exe --python-script "app.py" --no-splash --no-main-window

the code does not gets executed and the result is not obtained.

If the script is executed using the following command

Slicer.exe --python-script "app.py"

the result is generated but, the GUI appears.

I need to execute the script without opening GUI.

yes, the full Slicer GUI appears.
My Slicer version is 5.2.2

Everything works perfectly for me with Slicer-5.2.2 on Windows. If I create an app.py file with this content:

import slicer
slicer.util.messageBox('test')

And run this command:

"c:\Users\andra\appdata\Local\NA-MIC\Slicer 5.2.2\Slicer.exe" --no-splash --no-main-window --python-script "c:\Users\andra\appdata\Local\NA-MIC\Slicer 5.2.2\test.py"

then all I get is a popup window, displayed by app.py executed by Slicer. The Slicer main window is not displayed.

The messageBox appears while executing the code. But the other lines of code are not executed.

I have developed a python script which segments skull from dicom data.

I’m not sure what “other lines” you are referring to. If you provide an example script that is not executed the way you expect then we can investigate.

Note that Slicer.exe launcher is a GUI application, therefore it cannot print anything to the console. Maybe you think that some code lines are not sure executed because you don’t see the output in the console? See here how you can see the console output on Windows.