Hi, I’m developing an Extension in python to anonymize MRIs and I need to use some Freesurfer commands (mri_info, mris_convert and mri_watershed).
Is there a way to run Freesurfer commands from inside a Slicer Extension?
I’m using subprocess to perform the function calls but I get an error “non-zero exit status -6”. I tried the solution showed in Subprocess call in Python interpreter results in memory corruption, adding the binaries directory to the path as done in Elastix, and also using slicer.utils.startupEnvironment() but I can’t make it work.
If i do like that, I see the beginning of the output on the logfile (only 2 lines) but the process doesn’t continue (i.e. the surfaces are not created and htop shows no cpu usage). If I use subprocess.check_call() I also get the -6 error.
Any help would be greatly appreaciated, thanks.
Operating system: OSX 10.15.6
Slicer version: 4.10.2
Expected behavior: Using subprocess to run Freesurfer commands
Actual behavior: “non-zero exit status -6”
Please try with latest Slicer Preview Release.
Also, try the same command from a regular Python3 interpreter to see if the syntax of the call is correct.
I’m able to run freesurfer commands without problems. I’ll keep studying the problem and add any new insights and a more complete answer here for future reference. Thanks for all your help!
For this to work the freesurfer scripts and files required should be included in the right hierarchy or pointed to. For example on the code above I’m adding ‘%s/Resources/lib/gcc/lib’ % base_dir to ‘DYLD_LIBRARY_PATH’ and defining ‘%s/Resources’ % base_dir as ‘FREESURFER_HOME’.
The folder structure (including only the files relevant for this topic) in my case looks like this:
Note that you will need to add a freesurfer license.txt for the scripts to work.
It is also possible to find a permissions problem on Mac computers when trying to run freesurfer commands. If this happens, for example on my case, I had to go to the Resources → bin, or Resources → lib → gcc folder and double click on the command that I was unable to run (e.g. mri_watershed) and then going to System Preferences → Security & Privacy and allowing the execution from there (the window will show the last blocked command). If needed you will have to repeat the operation for each of the commands that are being blocked.