# Subprocess call in Python interpreter results in memory corruption

**URL:** <https://discourse.slicer.org/t/subprocess-call-in-python-interpreter-results-in-memory-corruption/919>\
**Category:** Support\
**Tags:** python\
**Created:** [August 22, 2017, 1:03pm UTC](https://discourse.slicer.org/t/subprocess-call-in-python-interpreter-results-in-memory-corruption/919 "2017-08-22T13:03:10Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [September 5, 2017, 8:37pm UTC](https://discourse.slicer.org/t/subprocess-call-in-python-interpreter-results-in-memory-corruption/919/15 "2017-09-05T20:37:21Z")

</div>

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):

```auto
>>> 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:

```auto
>>> from subprocess import check_output
>>> check_output(
  ["/usr/bin/python3", "-c", "print('hola')"], 
  env=slicer.util.startupEnvironment())
'hola\n'

```

---

_[View the full topic](https://discourse.slicer.org/t/subprocess-call-in-python-interpreter-results-in-memory-corruption/919)._
