Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
5.4.0 - English

Change language to:
Français - 日本語 - Português - Русский

Please note that the recommended version of Scilab is 2023.1.0. This page might be outdated.
See the recommended documentation of this function

Scilab help >> Advanced functions > execstr


execute Scilab code in strings

Calling Sequence

ierr=execstr(instr,'errcatch' [,msg])



vector of character strings, Scilab instruction to be executed.


integer, 0 or error number.


character string with values 'm' or 'n'. Default value is 'n'.


Executes the Scilab instructions given in argument instr.

Note that instr should not make use of continuation marks (..)

If the 'errcatch' flag is not present, error handling works as usual.

If the 'errcatch' flag is set, and an error is encountered while executing the instructions defined in instr, execstr issues no error message, but aborts execution of the instr instructions (at the point where the error occurred), and resumes with ierr equal to the error number. In this case the display of the error message is controlled by the msg option:


error message is displayed and recorded.


no error message is displayed, but the error message is recorded (see lasterror). This is the default.

ierr=execstr(instr,'errcatch') can handle syntactical errors. This is useful for evalution of instruction obtained by a query to the user.


execstr('a=1') // sets a=1.
execstr('1+1') // does nothing (while evstr('1+1') returns 2)

execstr(['if %t then';
         '  a=1';
         '  b=a+1';
         ' b=0'


//syntax errors

execstr('a=[1 2 3)','errcatch')

// variable1 does not exist
if execstr('variable1;','errcatch')<>0 then disp("Trigger an error"),end

// variable2 exists ... no error is triggered by execstr
if execstr('variable2;','errcatch')<>0 then 
   disp("Trigger an error");
   disp("execstr is happy");

See Also

  • evstr — evaluation of expressions
  • lasterror — get last recorded error message
  • error — error message
  • try — beginning of try block in try-catch control instruction
Report an issue
<< exec Advanced functions fun2string >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Oct 01 17:34:57 CEST 2012