东西在说...文件没有删除TCL
请记住,当我手动运行脚本时,但不是在通过任务计划程序运行脚本时,它会按预期工作。
我有一个TCL脚本,应该检查一个文件是否存在于网络驱动器上,如果存在则删除它。我这样做:
if {[file exists X:/path/to/file.txt]} {
log_output "Deleting file X:/path/to/file.txt"
file delete -force X:/path/to/file.txt
}
我注意到,通过任务计划程序运行时,文件永远不会被删除。于是我又进行了一次检查,试图获得更多信息。
if {[file exists X:/path/to/file.txt]} {
log_output "File X:/path/to/file.txt NOT DELETED!"
} else {
log_output "File X:/path/to/file.txt DELETED!"
}
我的输出是:
Deleting file X:/path/to/file.txt
File X:/path/to/file.txt DELETED!
第二行确认为已删除的存在检查失败的文件实际上是报道。最后,我运行一个生成新文件的命令。
exec myProgram --outFile X:/path/to/file.txt
再一次,奇怪的是当我手动运行这个脚本,它工作得很好。然而,当我把它设置为通过任务调度程序(使用Win7的),旧的文件不会被删除,即使输出日志显示它是运行:
Deleting file X:/path/to/file.txt
File X:/path/to/file.txt DELETED!
当我检查文件的日期和时间戳它总是从我上次执行手动运行开始。我认为这是更多的权限错误,但这没有意义。为什么它会报告为删除并仍然保持不变?
为了彻底,我尝试了一些其他的解决方法。相反,通过命令写一个文件到网络驱动器,我试图在本地写它:
if {[file exists C:/path/to/file.txt]} {
log_output "Deleting file C:/path/to/file.txt"
file delete -force C:/path/to/file.txt
}
if {[file exists C:/path/to/file.txt]} {
log_output "File C:/path/to/file.txt NOT DELETED!"
} else {
log_output "File C:/path/to/file.txt DELETED!"
}
exec myProgram --outFile C:/path/to/file.txt
然后将其复制到网络驱动器:
file copy -force C:/path/to/file.txt X:/path/to/file.txt
file copy -force C:/path/to/file.txt X:/path/to/file1.txt
我得到:
Deleting file X:/path/to/file.txt
File X:/path/to/file.txt DELETED!
Deleting file C:/path/to/file.txt
File C:/path/to/file.txt DELETED!
但是果然,旧文件仍然存在,并且新文件'file1.txt'不存在...
A增益,手动运行总是会导致成功。
调度任务中的文件映射很困难。使用UNC路径。 ('/ machine/share/path/to/file.txt') –
是的,我也试过。相同的结果。按预期手动运行。即使输出日志将文件显示为已删除,由Task Scheduler运行时仍然失败。 – radensb
计划任务是否有权删除该文件? –