# How should I pass arguments when running Slicer in batch mode?

**URL:** <https://discourse.slicer.org/t/how-should-i-pass-arguments-when-running-slicer-in-batch-mode/8217>\
**Category:** Support\
**Created:** [August 28, 2019, 8:44pm UTC](https://discourse.slicer.org/t/how-should-i-pass-arguments-when-running-slicer-in-batch-mode/8217 "2019-08-28T20:44:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hbraunDSP](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hbraundsp/32/4574_2.png) [@hbraunDSP](https://discourse.slicer.org/u/hbraunDSP)\
**Post date:** [August 28, 2019, 8:44pm UTC](https://discourse.slicer.org/t/how-should-i-pass-arguments-when-running-slicer-in-batch-mode/8217/1 "2019-08-28T20:44:56Z")

</div>

I want to run slicer from within python, to execute a script that builds a scene automatically from a JSON file telling it what files to load. I think I’ve solved everything except how to tell slicer the location of the JSON file. There are several options I can think of:

- Run `Slicer --python-script myscript.py`, first setting an environment variable `json_file` that is then checked by myscript.py.
- Run `Slicer --python-code mymodule.myscript(<json_file>)`, where my code inserts the correct string for \<json\_file\> before running slicer
- Same as above, but run `Slicer -c` instead of `Slicer --python_code`

All of these feel pretty kludgy for something that seems like it would be common. Is there some other way I’m not thinking of? Is there a preferred way to give arguments when running a python script within Slicer as part of a batch job?

---

<div class="post-metadata">

**Author:** ![Sam\_Horvath](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sam_horvath/32/3092_2.png) [@Sam\_Horvath](https://discourse.slicer.org/u/Sam_Horvath)\
**Post date:** [August 29, 2019, 3:24pm UTC](https://discourse.slicer.org/t/how-should-i-pass-arguments-when-running-slicer-in-batch-mode/8217/2 "2019-08-29T15:24:53Z")

</div>

Everything after --python-script until the next recognizable flag is passed into the python interpreter:

Run:  
`./Slicer.exe --no-main-window --python-script test.py param1 param2 param3`

Where test.py is:  
`print(sys.argv)`

You will get this output on the console:  
`['test.py', 'param1', 'param2', 'param3']`
