Index: source/creator/creator.c =================================================================== --- source/creator/creator.c (revision 18869) +++ source/creator/creator.c (working copy) @@ -234,6 +234,7 @@ printf (" -h\t\tPrint this help text\n"); printf (" -y\t\tDisable automatic python script execution (scriptlinks, pydrivers, pyconstraints, pynodes)\n"); printf (" -P \tRun the given Python script (filename or Blender Text)\n"); + printf (" -K \tRun the given Python script (filename or Blender Text), stopping and returning 1 to the shell if the script fails.\n"); #ifdef WIN32 printf (" -R\t\tRegister .blend extension\n"); #endif @@ -717,17 +718,25 @@ } break; case 'P': + case 'K': #ifndef DISABLE_PYTHON - a++; - if (a < argc) { - /* If we're not running in background mode, then give python a valid screen */ - if ((G.background==0) && (scr_init==0)) { - main_init_screen(); - scr_init = 1; + { + char option=argv[a][1]; + a++; + if (a < argc) { + /* If we're not running in background mode, then give python a valid screen */ + if ((G.background==0) && (scr_init==0)) { + main_init_screen(); + scr_init = 1; + } + if (!BPY_run_python_script (argv[a])) { + if (option=='K') { + G.afbreek=1;//stop and return error to shell + } + } } - BPY_run_python_script (argv[a]); + else printf("\nError: you must specify a Python script after '-%c '.\n",option);//-P or -K } - else printf("\nError: you must specify a Python script after '-P '.\n"); #else printf("This blender was built without python support\n"); #endif /* DISABLE_PYTHON */ Index: source/blender/python/BPY_extern.h =================================================================== --- source/blender/python/BPY_extern.h (revision 18869) +++ source/blender/python/BPY_extern.h (working copy) @@ -94,7 +94,7 @@ int BPY_menu_do_python( short menutype, int event ); int BPY_menu_do_shortcut( short menutype, unsigned short key, unsigned short modifiers ); int BPY_menu_invoke( struct BPyMenu *pym, short menutype ); - void BPY_run_python_script( const char *filename ); + int BPY_run_python_script( const char *filename ); int BPY_run_script(struct Script *script); void BPY_free_compiled_text( struct Text *text ); Index: source/blender/python/BPY_interface.c =================================================================== --- source/blender/python/BPY_interface.c (revision 18869) +++ source/blender/python/BPY_interface.c (working copy) @@ -738,13 +738,14 @@ * Description: Called from command line to run a Python script * automatically. The script can be a file or a Blender Text in the current * .blend. +* Returns 1 on success, 0 on fail ****************************************************************************/ -void BPY_run_python_script( const char *fn ) +int BPY_run_python_script( const char *fn) { char filename[FILE_MAXDIR + FILE_MAXFILE]; Text *text = NULL; int is_blender_text = 0; - + int return_value=0; BLI_strncpy(filename, fn, FILE_MAXDIR + FILE_MAXFILE); if (!BLI_exists(filename)) @@ -764,7 +765,7 @@ if (text == NULL) { printf("\nError: no such file or Blender text -- %s.\n", fn); - return; + return return_value; } else is_blender_text = 1; /* fn is already a Blender Text */ } @@ -781,7 +782,7 @@ /* Chris: On Windows if I continue I just get a segmentation * violation. To get a baseline file I exit here. */ exit(2); - /* return; */ + /* return return_value; */ } } @@ -789,6 +790,9 @@ printf("\nError executing Python script from command-line:\n" "%s (at line %d).\n", fn, BPY_Err_getLinenumber()); } + else { + return_value=1; + } if (!is_blender_text) { /* We can't simply free the text, since the script might have called @@ -798,6 +802,7 @@ free_libblock(&G.main->text, text); } } + return return_value; } int BPY_run_script(Script *script)