2
$\begingroup$

I am running a python expression through blender from the commandline. I want to know if the python expression is executed correctly or not. But Blender always exits with a 0 code. Is there any way to make it exit with the same code as the python expression?

For example I would expect the following command exit with a non-zero code:

"\Program Files\blender foundation\blender\blender.exe" --background --python-expr "2/0"
$\endgroup$

2 Answers 2

2
$\begingroup$

You will have to put the expr in try and explicitly exit with an error code on exception.

E.g. following exits with exit code 10 (user defined):

"\Program Files\blender foundation\blender\blender.exe" --background --python-expr "exec('import sys\ntry: 2/0\nexcept: sys.exit(10)')"
$\endgroup$
1
$\begingroup$

Using the flag --python-exit-code seems to work okay, at least for unix-based CLI ↓

blender --factory-startup -b your.blend --python-exit-code 1 -P your.py

echo $?
$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.