exec - Script file execution


Syntax

exec(path [,mode])
exec(fun [,mode])
ierr = exec(path, 'errcatch' [,mode])
ierr = exec(fun, 'errcatch' [,mode])
[ierr, errormsg] = exec(..., 'errcatch' [,mode])
[ierr, errormsg, callstack] = exec(..., 'errcatch' [,mode])

Arguments

path

a string, the path of the script file.

mode

an integer scalar, the execution mode (see below).

fun

a Scilab function.

ierr

an integer, 0 or error number.

errormsg

error message in case of error and with 'errcatch' flag.

callstack

callstack in case of error and with 'errcatch' flag.

Description

exec(path [,mode]) executes sequentially the Scilab instructions contained in the file given by path with an optional execution mode mode.

The different cases for mode are :

0

the default value.

-1

nothing is printed.

1

echo of each command line.

2

prompt --> is printed.

3

echoes + prompts.

4

stops before each prompt. Execution resumes after a carriage return.

7

stops + prompts + echoes : useful mode for demos.

exec(fun [,mode]) executes function fun as a script: no input nor output argument nor specific variable environment. This method for script evaluation allows to store scripts as function in libraries.

If an error is encountered while executing, if 'errcatch' flag is present exec issues no error message, aborts execution of the instructions and resumes with ierr equal to the error number. If 'errcatch' flag is not present, standard error handling works.

Remarks

exec files may now be used to define functions using the inline function definition syntax (see function).

exec supports files encoded as ANSI/ASCII and UTF-8.

The length of each line in a file is limited to 4096 characters.

Examples

mputl('a=1;b=2',TMPDIR+'/myscript')


exec(TMPDIR+'/myscript')
whos -name "a "


deff('y=foo(x)','a=x+1;y=a^2')
clear a b

foo(1)


whos -name "a "

x=1 
exec(foo)


whos -name "a "
whos -name "y "


mputl('acosd(''d'');', TMPDIR+'/myscript')
[_ b] = exec(TMPDIR+'/myscript', 'errcatch')

See also

  • execstr — execute Scilab code in strings
  • evstr — evaluates Scilab expressions and concatenates their results
  • mode — sets or queries the mode echoing Scilab instructions in the console
  • chdir — changes Scilab current directory
  • pwd — gets Scilab current directory