ENH: Extend application API adding environment()/startupEnvironment()
Created by: jcfr
With the upcoming feature, it will be possible to easily invoke processes by excluding the Slicer environment.:
- from c++ (using
app->startupEnvironment()
), or; - from python (using
slicer.util.startupEnvironment()
Here are two examples:
Without using the startup
environment, this first example fails (as expected):
>>> from subprocess import check_output
>>> check_call(["/usr/bin/python3", "-c", "print('hola')"])
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/jcfr/Projects/Slicer-2-build/python-install/lib/python2.7/subprocess.py", line 186, in check_call
raise CalledProcessError(retcode, cmd)
CalledProcessError: Command '['/usr/bin/python3', '-c', "print('hola')"]' returned non-zero exit status -6
Now, using the sanitized environment, this one succeeds:
>>> from subprocess import check_output
>>> check_output(
["/usr/bin/python3", "-c", "print('hola')"],
env=slicer.util.startupEnvironment())
'hola\n'