End the blender with exit code "1" when starting from the command line

I am working with an automated python blender script and I would like to know how to complete it with Exit Code 1 when an exception occurs.

The problem is that the exit code from the blender is always 0, even if the python script fails.

The following script definitely creates a non-zero exit code, but the blender sets the exit code to 0

def main():
    raise Exception("Fail")
    sys.exit(1)

I also tried the command line argument -python-exit-code, but had no effect:

C:\blender.exe --python-exit-code 2 --disable-abort-handler -P bake.py

this gives a slightly better result, because I get the following message:

Error: script failed, file: 'bake.py', exiting with code 2.

Unfortunately, the exit code is still 0.

Can someone enlighten me with some explanations or decisions on how I can exit the process with the correct exit code?

Thanks so much for any tips!

+4
1

--python-exit-code, , , script, --python , .

[0..255] , Python ( , ), .

, - , except. ( , 0.

blender.

import unittest
from tests.my_test import MyTest
import sys

def run():
    suite = unittest.defaultTestLoader.loadTestsFromTestCase(MyTest)
    success = unittest.TextTestRunner().run(suite).wasSuccessful()
    if not success:
        raise Exception('Tests Failed')

try:
    run()
except Exception:
    sys.exit(1)
+4

Source: https://habr.com/ru/post/1625320/


All Articles