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

标签 windows perl clearcase xcopy psexec

我正在使用 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.

xcopy 是通过 system() 还是反引号调用似乎没有区别。

我应该指出,“from”文件夹是一个 ClearCase 动态 View (M 盘)。

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

这里还有一些奇怪的地方:

  1. xcopy 并不总是失败。某些文件似乎被“诅咒”了。只读属性似乎不是一个因素。

  2. 一旦复制成功(例如,通过 Windows 资源管理器),诅咒就会解除,该特定文件将不再导致 xcopy 错误。

  3. 问题似乎与目标文件夹无关。一旦诅咒解除,文件就可以 xcopy 到新的目的地。

以下是我用来缩小问题范围的测试 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

最佳答案

我建议您不要使用 xcopy 命令,而是使用 Perl 本身进行复制。有一个模块 File::Copy::Recursive这很容易使用。它不是标准 Perl 发行版的一部分,因此您必须使用 cpan 安装它。

如果你不想使用非原生模块,你可以尝试使用File::Find在目录中查找文件,然后将其与 File::Copy 组合.

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

是的,这不是直接回答你的问题,但你应该尽可能避免使用 system 命令。当您与系统 shell 和命令处理器交互时(尤其是当 ClearCase 破解文件系统时),您最终可能会遇到许多无意的交互,这些交互可能会导致某些东西在某些情况下起作用,但不会其他。

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

关于windows - 为什么 Windows XCOPY 在通过 psexec 通过 Perl 系统调用调用时失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10526486/

相关文章:

java - 用于测试自动化的 ClearCase 结构

perl - 如何扩展文本字符串中的变量?

java - 尝试更改时出现设置构建路径错误

windows - 将所有批处理文件参数转发给内部命令

windows - 在 Windows 中 grep unicode 文本文件的免费程序?

perl - NET::FTP 在 perl 中放置命令

perl - 如何以隐藏方式获取字符串

linux - Eclipse CDT Linux ClearCase SCM Adapter 插件安装问题

windows - 无法通过 wmic 启动 npm

windows - 无法创建数据目录 - Google Chrome 无法读取和写入其数据目录 - Cordova