使用 TCL 中的文件属性授予文件权限

Giving permission to file using file attributes in TCL

我有一个 client.exe 可执行文件,它将自己替换为以“autoupdate-client.exe 开头的文件。 例如:如果 client.exe 运行并且 autoupdate-client.exe 在同一文件夹中,则程序将删除 client.exe 并将 autoupdate-client.exe 重命名为 client.exe。以下代码在widows中实现:

if {[regexp -nocase \
"autoupdate-(.*)" \
[file tail [info nameofexecutable]] - binaryname]} {
after 5000
set dirname [file dirname [info nameofexecutabe]
set targetname [file join $dirname $binaryname]
catch {vfs::mk4::Unmount exe [info nameofexecutable]]
file copy -force [infor nameofexecutable] $targetname
catch {file attributes $targetname -permission 0755}
exec $targetname {*}$argv &
exit 0
} else {
set dirname [file dirname [infor nameofexecutable]
set targetname [file join $dirname \
"autoupdate-[file tail [info nameofexecutablle]]}\
]
if {[file exists $targetname]} {

5000之后 赶上 {file delete -force $targetname}

我收到以下错误:

error copying "autoupdate-client.exe" to "client.exe": permission denied
while executing "
file copy -force [info nameofexecutable] $targetname"

我怀疑文件属性 $targetname -permission 0755 出错了。 我想知道如何在 windows

中授予权限

对于windows,您需要进行以下步骤:

# Rename the original file to a new name.
file rename -force client.exe client-old.exe
# Rename (or copy) the new file to the target name.
file rename -force autoupdate-client.exe client.exe
# Now (try) to remove the old file
catch { file delete -force client-old.exe }

不能保证此时可以删除旧的可执行文件。您可能需要稍后将其删除。

C:\Users\bll\Desktop\BallroomDJ\windows\tcl\bin>copy tclsh.exe t1.exe
        1 file(s) copied.
C:\Users\bll\Desktop\BallroomDJ\windows\tcl\bin>copy tclsh.exe t2.exe
        1 file(s) copied.
C:\Users\bll\Desktop\BallroomDJ\windows\tcl\bin>.\t1.exe
% file rename -force t1.exe t1-old.exe
% file rename -force t2.exe t1.exe
% file delete -force t1-old.exe
error deleting "t1-old.exe": permission denied
% exit
C:\Users\bll\Desktop\BallroomDJ\windows\tcl\bin>dir t*.exe
 Directory of C:\Users\bll\Desktop\BallroomDJ\windows\tcl\bin
2017-10-23  10:37           453,579 t1-old.exe
2017-10-23  10:37           453,579 t1.exe
2017-10-23  10:37           453,579 tclsh.exe
C:\Users\bll\Desktop\BallroomDJ\windows\tcl\bin>

编辑:

Windows 没有执行权限的概念。 file attributes 命令可能与您的想法不符。