How to gracefully exit from command line error

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 25/11/2009 at 03:50, xxxxxxxx wrote:

Originally posted by xxxxxxxx

I have no idea how to cause C4D to exit from a plugin.  There is a C4DPL_ENDPROGRAM command but not sure if it is possible (or allowed) to send it from a plugin.

Just tried this, CallCommand(12104) will do it - that's the Quit C4D command. Seems to work fine (tested in R10). Of course, this assumes Cinema has completed loading and the user calls the plugin. I don't know if it would work before then.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 25/11/2009 at 08:06, xxxxxxxx wrote:

I think he wants to preemptively quit C4D so I was looking for a way to do that.  The Quit command may or may not work if done at such an early stage.  We'll see. 🙂

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 25/11/2009 at 08:23, xxxxxxxx wrote:

Yes, I thought that might be a problem with that method. I've just tried it. Putting the CallCommand() in PluginStart simply hangs Cinema, and the process has to be terminated in task manager (not unexpected!). Putting it in PluginMessage, case C4DPL_COMMANDLINEARGS, doesn't seem to have any effect.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 25/11/2009 at 08:50, xxxxxxxx wrote:

Originally posted by xxxxxxxx

_ _ ____P.S., how do you enter code snippets in this fancy new RichText Editor?

It's done with CODE tags have a look a your first post. I edited it.

cheers,
Matthias

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 25/11/2009 at 08:52, xxxxxxxx wrote:

As for the original question, I have to ask the developers about it.

cheers,
Matthias

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 30/11/2009 at 14:58, xxxxxxxx wrote:

Oh, I'm sorry I did not provide enough information.

In this case, Cinema4D is running in batch mode (-nogui) remotely, processing hundreds of textures. It is a small part of a much larger rendering job.

Of course, I could write a script that would launch the job, first checking to make sure all command line arguments are valid. But unfortunately the code that launches Cinema4D is part of a larger system that cannot be modified at this time. Also, this would only apply if there were a problem with the command line. I'd still need a way to gracefully exit if an error occured after the command line was successfully parsed.

Currently, we throw an exception whenever an error occurs, but we *know* this isn't the correct approach (as indicated by the comment in the code snippet of the original post). The uncaught exception is handled by a post processor, which is unable to properly interpret the crash log.

We need something that will immediately exit Cinema4D with some sort of an error code.

I just saw C4DPL_ERROR in the SDK, would it be safe to send that?

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 04/12/2009 at 06:34, xxxxxxxx wrote:

Please try to execute

  
CallCommand(12104);  

or

  
UWORD empty[2];  
empty[0]=empty[1]=0;  
RestartApplication(empty);  

cheers,
Matthias

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 04/12/2009 at 12:14, xxxxxxxx wrote:

Hi Matthias,

I tried both of the solutions that you recommended, and they both exit gracefully, which is good.

However, in both cases C4D exits with code 0. The script that started the C4D job thinks the job was successful and so it launches the next job. This is not good.

Here is a snipped from our python script:

  
cmd = 'CINEMA_4D -nogui -camspref'   
retval = os.system(cmd)   
if (retval) :   
    print 'ERROR: C4D command did not complete successfully'   
    sys.exit(1)   
else:   
    # Launch compositing job   

Is there anything I can set so that C4D exits and returns non zero to the system?

Thanks!

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 04/12/2009 at 12:16, xxxxxxxx wrote:

One other note I'd like to mention: We have the same problem when C4D errorors out during a reander (as opposed to during plugin execution). C4D prints a message that the render failed, but then exits and returns 0 to the system (instead of an error code).

Does C4D always return 0 when it exits?

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 07/12/2009 at 03:48, xxxxxxxx wrote:

You can pass an exit code to RestartApplication.

  
void RestartApplication(const UWORD *param = NULL, LONG exitcode = NULL, const UWORD **path = NULL)  

cheers,
Matthias