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.
Here is an example code:
... def getFsEnv(self): fsBinDir = '/path/to/binaries' fsEnv = os.environ.copy() fsEnv["PATH"] = fsBinDir + os.pathsep + fsEnv["PATH"] if fsEnv.get("PATH") else fsBinDir ... fsEnv=self.getFsEnv() subprocess.check_output(shlex.split('mri_info /path/to/file.mgz'), env=fsEnv)
I’ve also tried with subprocess.Popen(). In this case I think it starts and then stops:
logfile=open("filename", "w") subprocess.Popen(shlex.split('mri_watershed -useSRAS -surf /path/ /file.mgz /path'), env=fsEnv, stdout=logfile) logfile.close()
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”