# HG changeset patch # User Rik # Date 1467562891 25200 # Node ID 98ee8b1ebbebe52a522ff6cf3013f4fb44fedb6e # Parent 91611c9e1d81efe1cc908a59d4c59c402dc1e6ba run.m: Return to original directory after executing script (bug #48351). * run.m: Don't use make_absolute_filename(). Instead, return to the original directory whenever we find ourselves still in the scriptdir after execution. Put input validation error messages ahead of main body of code. diff -r 91611c9e1d81 -r 98ee8b1ebbeb scripts/miscellaneous/run.m --- a/scripts/miscellaneous/run.m Sat Jul 02 20:47:47 2016 -0700 +++ b/scripts/miscellaneous/run.m Sun Jul 03 09:21:31 2016 -0700 @@ -59,21 +59,23 @@ endif if (! isempty (d)) - if (exist (d, "dir")) - startdir = pwd (); - d = make_absolute_filename (d); - unwind_protect - cd (d); - evalin ("caller", sprintf ("source ('%s%s');", f, ext), - "rethrow (lasterror ())"); - unwind_protect_cleanup - if (strcmp (d, pwd ())) - cd (startdir); - endif - end_unwind_protect - else + if (! exist (d, "dir")) error ("run: the path %s doesn't exist", d); endif + + startdir = pwd (); + scriptdir = ""; + unwind_protect + cd (d); + scriptdir = pwd (); + evalin ("caller", sprintf ("source ('%s%s');", f, ext), + "rethrow (lasterror ())"); + unwind_protect_cleanup + if (strcmp (scriptdir, pwd ())) + cd (startdir); + endif + end_unwind_protect + else if (! isempty (ext)) script = which (script);