help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Error in run command?


From: Richardson, Anthony
Subject: Error in run command?
Date: Wed, 10 Jun 2015 16:20:20 +0000

In 4.0.0 for Windows, when the run command is executed as:

 

                run(‘subdir/mfile.m’)

 

Then you are left in directory ‘subdir’ after the run command completes.

According to the documentation for run, you should be returned to the original directory unless the script specifically changes the directory (in my program it does not).

 

The error appears to be in line 70 of the run.m script:

 

if (strcmp (d, pwd ()))

 

The comparison should return TRUE, but returns FALSE because d contains a single ‘/’ directory separator (as a result of generating the full pathname using canonicalize_file_name) while pwd contains a path containing all back-slashes ‘\’.

 

run(‘subdir\mfile.m’) exhibits the same behavior.  I would expect this to be an error only under Windows.

 

I fixed the error by replacing the following lines in run.m (around line 65):

 

      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

 

 

with the following lines:

 

      unwind_protect

        cd (d);

        dcmp = pwd ();              % Added line

        evalin ("caller", sprintf ("source ('%s%s');", f, ext),

                "rethrow (lasterror ())");

      unwind_protect_cleanup

        if (strcmp (dcmp, pwd ()))          % Changed line

          cd (startdir);

        endif

     end_unwind_protect

 

This doesn’t seem like an elegant solution.  Is this error in run actually caused by an underlying error in canonicalize_file_name, which I would expect to return a path containing all ‘\’s instead of a mix of ‘\’s and ‘/’?

 

By the way, I noticed this problem when loading the ltfat package.  The ltfat load script calls run several times and leaves me in a strange directory.

 

Tony Richardson

 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]