Citizen Insane - 2006-06-21

Hello,

Here is an "SecureEval" method you may add to your library in order to double-check that commands send to Matlab are correctly interpreted.

public void SecureEval(string cmd)
{
    // Reset errors
    Eval("lasterror('reset');");

    // Send the command
    Eval(cmd);

    // Check for errors with unlikely
    // user variable names
    Eval("_err_ = lasterror;");
    Eval("_err_msg_ = _err_.message;");
    Eval("_err_identifier_ = _err_.identifier;");
    Eval("_err_stack_ = _err_.stack";);
    string err_msg = GetVariable<string>("_err_msg_");
    string err_id = GetVariable<string>("_err_identifier_");
    Stack err_stack = GetVariable<Stack>("_err_stack_");

    if (err_msg.Length != 0)
    {
       throw MatlabCommandException(err_id, err_msg, err_stack);
    }
}

NB: Carefull, pseudo-code not tested

BR,
Stéphane