我正在使用psexec在远程Windows机器上启动Perl程序。该程序对xcopy进行系统调用。当直接在机器上运行时,这很好用,但是通过psexec远程运行时,xcopy会失败,并显示以下消息:
文件创建错误-函数不正确。
(根据用户,消息可能改为“拒绝访问”。)
请注意,$!给出以下诊断:
syscall.pl处的坏文件描述符。 Perl以错误代码9退出。
无论是通过system()还是反引号调用xcopy似乎都没有区别。
我应该指出,“from”文件夹是ClearCase动态视图(M驱动器)。
奇怪的是,当直接从psexec调用xcopy时,它似乎能正常工作。
以下是一些其他奇怪之处:
1. xcopy并不总是失败。某些文件似乎只是“被诅咒”的。只读属性似乎不是因素。
2. 一旦复制成功(例如通过Windows资源管理器),诅咒就会解除,那个特定的文件将不再导致xcopy错误。
3. 问题似乎不在目标文件夹中。一旦解除了诅咒,文件可以复制到新目标。
以下是我用于缩小问题范围的测试Perl脚本的一部分(文件夹名称已经通用化)。请注意,对于每个“my $cmd”进行测试,我都注释掉了以前的命令,并添加了状态注释。
文件创建错误-函数不正确。
(根据用户,消息可能改为“拒绝访问”。)
请注意,$!给出以下诊断:
syscall.pl处的坏文件描述符。 Perl以错误代码9退出。
无论是通过system()还是反引号调用xcopy似乎都没有区别。
我应该指出,“from”文件夹是ClearCase动态视图(M驱动器)。
奇怪的是,当直接从psexec调用xcopy时,它似乎能正常工作。
以下是一些其他奇怪之处:
1. xcopy并不总是失败。某些文件似乎只是“被诅咒”的。只读属性似乎不是因素。
2. 一旦复制成功(例如通过Windows资源管理器),诅咒就会解除,那个特定的文件将不再导致xcopy错误。
3. 问题似乎不在目标文件夹中。一旦解除了诅咒,文件可以复制到新目标。
以下是我用于缩小问题范围的测试Perl脚本的一部分(文件夹名称已经通用化)。请注意,对于每个“my $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
system ($cmd) or die "'$cmd' failed: $!";
这个命令,它会告诉你错误信息(如果存在的话),我认为这比你的打印命令更可靠。 - Barton Chittendensystem
成功,它只会打印$!
。相反,使用system ($cmd) and die "'$cmd' failed: $!"
。有关详细信息,请参见perldoc -f system。另外,使用我建议的LIST
形式。 - Sinan Ünür$!
,却忽略了这一点。 - Barton Chittenden