1 ## Copyright (C) 2007-2012 David Bateman
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Command} {} run @var{script}
21 ## @deftypefnx {Function File} {} run (@var{script})
22 ## Run scripts in the current workspace that are not necessarily on the
23 ## path. If @var{script} is the script to run, including its path, then
24 ## @code{run} changes the directory to the directory where @var{script} is
25 ## found. @code{run} then executes the script, and returns to the original
36 [d, f, ext] = fileparts (script);
42 if (! exist (cstrcat (f, ext), "file"))
43 error ("run: file SCRIPT must exist and be a valid Octave scriptfile");
45 evalin ("caller", sprintf ("source (\"%s%s\");", f, ext),
46 "rethrow (lasterror ())");
47 unwind_protect_cleanup
51 error ("run: the path %s doesn't exist", d);
54 if (exist (script, "file"))
55 evalin ("caller", sprintf ("source (\"%s\");", script),
56 "rethrow (lasterror ())");
58 error ("run: %s not found", script);