我正在使用 psexec 在远程 Windows 机器上启动 Perl 程序。该程序对 xcopy 进行系统调用。当直接(本地)在机器上运行时,这工作正常,但是当通过 psexec 远程运行时,xcopy 失败并显示以下消息:
文件创建错误 - 功能不正确。
(根据用户的不同,消息可能改为“拒绝访问”。)
请注意 $! 给出以下诊断:
syscall.pl 上的文件描述符错误。perl 在 REMOTE 上退出,错误代码为 9。
是否通过 system() 或反引号调用 xcopy 似乎没有区别。
我应该指出,“发件人”文件夹是一个 ClearCase 动态视图(M 驱动器)。
奇怪的是,当直接从 psexec 调用时,xcopy 似乎工作正常。
以下是一些其他的怪事:
xcopy 并不总是失败。某些文件似乎只是被“诅咒”了。只读属性似乎不是一个因素。
一旦复制成功(例如,通过 Windows 资源管理器),诅咒就会解除,并且该特定文件将不再导致 xcopy 错误。
问题似乎与目标文件夹无关。一旦诅咒解除,文件就可以被复制到一个新的目的地。
以下是我用来缩小问题范围的测试 Perl 脚本的一部分(文件夹名称已通用化)。请注意,对于每个测试的“我的 $cmd”,我注释掉了前一个,并添加了状态注释。
# ClearCase directory M:\STUFF\ABC contains ABC.tst, ABC.zip and several nonempty subfolders
# Directory copy, D drive to D drive
#my $cmd = "xcopy D:\\temp\\src D:\\temp\\dest /e /i /y";
# works
# Directory copy, M drive to D drive
#my $cmd = "xcopy M:\\STUFF\\ABC D:\\temp\\dest /e /i /k /y";
# fails with "File creation error - Incorrect function" or "Access denied"
# File copy (.tst), M drive to D drive (trailing backslash)
#my $cmd = "xcopy M:\\STUFF\\ABC\\ABC.tst D:\\temp\\dest\\";
# works!
# Directory copy, M drive to D drive (trailing backslash)
#my $cmd = "xcopy M:\\STUFF\\ABC D:\\temp\\dest\\ /e /i /k /y";
# copies the .tst file, but fails on the .zip (yes, the .tst file is now getting copied)
# Directory copy, M drive to D drive (same as above but without trailing backslash)
#my $cmd = "xcopy M:\\STUFF\\ABC D:\\temp\\dest /e /i /k /y";
# copies the .tst file, but fails on the .zip
# File copy (.zip), M drive to D drive
#my $cmd = "xcopy M:\\STUFF\\ABC\\ABC.zip D:\\temp\\dest";
# fails
# File copy (.zip), M drive to D drive (trailing backslash)
#my $cmd = "xcopy M:\\STUFF\\ABC\\ABC.zip D:\\temp\\dest\\";
# fails
# After manually (Windows Explorer) copying the .zip file to the dest folder and deleting it
# Directory copy, M drive to D drive with /c (continue after failure)
#my $cmd = "xcopy M:\\STUFF\\ABC D:\\temp\\dest /c /i /e";
# copies the .tst and .zip file (!), but fails on all other files (folders were successfully created)
# After manually copying the Folder1 folder to the dest folder and then deleting it
#my $cmd = "xcopy M:\\STUFF\\ABC D:\\temp\\dest /c /i /e";
# copies the .tst and .zip file and the contents of Folder1(!), but fails on all other files
# Different dest:
my $cmd = "xcopy M:\\STUFF\\ABC D:\\temp\\dest1 /c /i /e";
# Same results as immediately above
print "Executing system command: $cmd ...\n";
system ($cmd);
#print(`$cmd 2>&1`); #same