加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

为什么Windows XCOPY在通过psexec通过Perl系统调用调用时失败?

发布时间:2020-12-13 22:32:43 所属栏目:Windows 来源:网络整理
导读:我正在使用psexec在远程 Windows机器上启动Perl程序.该程序对xcopy进行系统调用.这在机器上直接(本地)运行时工作正常,但是当通过psexec远程运行时,xcopy失败并显示以下消息: File creation error – Incorrect function. (根据用户的不同,该消息可能改为“
我正在使用psexec在远程 Windows机器上启动Perl程序.该程序对xcopy进行系统调用.这在机器上直接(本地)运行时工作正常,但是当通过psexec远程运行时,xcopy失败并显示以下消息:

File creation error – Incorrect function.

(根据用户的不同,该消息可能改为“拒绝访问”.)

注意$!给出以下诊断:

Bad file descriptor at syscall.pl.
perl exited on REMOTE with error code 9.

是否通过system()或反引号调用xcopy似乎没有区别.

我应该指出“from”文件夹是一个ClearCase动态视图(M盘).

奇怪的是,当直接从psexec调用时,xcopy似乎正常工作.

以下是其他一些奇怪之处:

> xcopy并不总是失败.某些文件似乎只是“被诅咒”.只读属性似乎不是一个因素.
>一旦复制成功(例如,通过Windows资源管理器),解除诅咒,该特定文件将不再导致xcopy错误.
>问题似乎与目标文件夹不一致.解除诅咒后,可以将文件xcopy到新目的地.

以下是我用来缩小问题的测试Perl脚本的一部分(文件夹名称已经通用化).
请注意,对于每个测试的“my $cmd”,我都会注释掉前一个,并添加了状态注释.

# ClearCase directory M:STUFFABC contains ABC.tst,ABC.zip and several nonempty subfolders

# Directory copy,D drive to D drive
#my $cmd = "xcopy D:tempsrc D:tempdest /e /i /y";
# works

# Directory copy,M drive to D drive
#my $cmd = "xcopy M:STUFFABC D:tempdest /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:STUFFABCABC.tst D:tempdest";
# works!

# Directory copy,M drive to D drive (trailing backslash)
#my $cmd = "xcopy M:STUFFABC D:tempdest /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:STUFFABC D:tempdest /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:STUFFABCABC.zip D:tempdest";
# fails 

# File copy (.zip),M drive to D drive (trailing backslash)
#my $cmd = "xcopy M:STUFFABCABC.zip D:tempdest";
# 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:STUFFABC D:tempdest /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:STUFFABC D:tempdest /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:STUFFABC D:tempdest1 /c /i /e";
# Same results as immediately above

print "Executing system command: $cmd ...n";
system ($cmd);
#print(`$cmd 2>&1`); #same

解决方法

我建议您使用Perl本身而不是使用xcopy命令.有一个模块 File::Copy::Recursive,使用起来非常简单.它不是标准Perl发行版的一部分,因此您必须使用cpan进行安装.

如果您不想使用非本机模块,可以尝试使用File::Find查找目录中的文件,然后将其与File::Copy结合使用.

在Perl Monks上找到了两个示例.一个使用组合,另一个使用File :: Copy :: Recursive

是的,这不是直接回答您的问题,但您应该尽可能避免使用系统命令.当您与系统shell和命令处理器进行交互时(特别是当ClearCase使用文件系统进行攻击时),您最终可能会遇到许多无意的交互,这些交互可能会导致某些情况下的某些情况发生,而其他情况则不然.

要找出系统调用所遇到的问题,您必须假设错误可能在ClearCase,cmd.exe shell,xcopy命令或Perl中.通过不使用系统命令,您已经简化了问题,并且很多时候实际上加快了过程.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读