ActiveState Community

file delete problems

Posted by niobe on 2009-10-06 21:19

[file delete] works fine from the tclsh, but fails from my script.

%set inFile
C:/Documents and Settings/ben/.hosts
%file delete $inFile

..file disappears

In my script:

expect {
  "y\n" {
    if { [catch {file delete -force $::inFile} catchError] } {
      puts "catchError:\n$catchError"
      exit 1
    }
  }
  timeout {
    exit 1
  }
}

The result is an error:

catchError:
error deleting "C:/Documents and Settings/ben/.hosts": permission denied

Since this may have something to do with the spaces in inFile, I try quoting it (note that spaces didn't bother tclsh):

expect {
  "y\n" {
    if { [catch {file delete -force \"$::inFile\"} catchError] } {
      puts "catchError:\n$catchError"
      exit 1
    }
  }
  timeout {
    exit 1
  }
}

Now NO error is caught and the operation appears to succeed, but the file always remains in place.

The same occurs if I use [file normalise $::inFile] or [file nativename $::inFile]

jeffh | Wed, 2009-10-07 09:54

I suspect your script is operating under different user settings. The 2nd case where you get no error using \"s is bogus, because the -force is just ignoring that the filename doesn't exist. The spaces are not an issue because you are already calling it correctly with the variable. You might also check if $::errorCode gives a bit more info at the time of the error.

niobe | Wed, 2009-10-07 16:22

Hi Jeff,

errorCode:
POSIX EACCES {permission denied}

The script and shell are being running by the same user and the file is not read-only. Are there any other settings I should be looking at?

Also I am running my script from a windows cmd prompt with 'tclsh script.tcl'. I don't know if that could have anything to do with it, but since .tcl associates with wish this is my workaround.

jeffh | Wed, 2009-10-07 18:06

Can you please check that $::tcl_platform(user) is the same in both, as is the $::tcl_patchLevel? It may be a difference in versions as Tcl had some Windows ACL issues at various versions.

niobe | Wed, 2009-10-07 20:48

same on both unfortunately..

% puts $::tcl_platform(user)
ben
% puts $::tcl_patchLevel
8.5.7