这是一篇比较绕的文章,请耐心看完。我有一个 Perl 脚本,它位于 Windows VirtualBox 客户机上。我希望从 Linux 主机调用此脚本,并让它读取主机上的共享文件夹。然而,读取文件夹失败了。
在主机上,我调用此脚本并得到以下输出:
脚本将参数
当我从客户端直接使用相同的选项运行此脚本时,我会得到以下结果:
等等,情况变得更加奇怪了。当我不提供共享目录E:\,而是将其指向C:\时,它可以毫无问题地读取该目录并继续执行。因此,只有当我通过VirtualBox从主机运行命令并将其指向共享文件夹时才会出现错误。
这是相关的代码:
在主机上,我调用此脚本并得到以下输出:
host:~/$ ./script.pl /nfs/nasi/temp
[2014-04-02 10:50:55] Uploading file records to localhost
[2014-04-02 10:50:55] Running VirtualBox for Kaspersky
fatal: opendir(E:\nasi\temp) failed: No such file or directory
[2014-04-02 10:50:56] Uploading malware samples data to localhost
host:$
脚本将参数
/nfs/nasi/temp
转换为E:\nasi\temp
,并使用以下命令调用脚本:/usr/bin/VBoxManage guestcontrol <guest> execute \
--image "C:\strawberry\perl\bin \perl.exe" \
--username <user> --password <pass> \
--wait-stdout --wait-stderr --wait-exit -- \
"C:\antivirus\kaspersky.pl" "E:\nasi\temp"
当我从客户端直接使用相同的选项运行此脚本时,我会得到以下结果:
C:\antivirus>C:\strawberry\perl\bin\perl.exe C:\antivirus\kaspersky.pl E:\nasi\temp
[2014-04-02 10:54:19] Running Kaspersky Antivirus
[2014-04-02 10:54:20] Parsing Kaspersky report
[2014-04-02 10:54:20] Uploading Kaspersky results to 10.0.0.1
C:\antivirus>
等等,情况变得更加奇怪了。当我不提供共享目录E:\,而是将其指向C:\时,它可以毫无问题地读取该目录并继续执行。因此,只有当我通过VirtualBox从主机运行命令并将其指向共享文件夹时才会出现错误。
这是相关的代码:
sub createSamplesMap {
opendir( my $dh, $ARGV[0] ) or
die "fatal: opendir($ARGV[0]) failed: $!\n";
my @files = readdir( $dh );
foreach my $file ( @files ) {
if (! -d $file ) {
...
}
}
closedir($dh);
}
我尝试了不同的方法从目录中读取文件名,但它们都没有成功。这是我尝试过的方法。
my @files = <$ARGV[0]\\*>;
my @files = glob( $ARGV[0] . '\\*' );
我不知道是要责怪Perl还是VirtualBox。有人对问题有什么想法吗?
- Windows 7,草莓Perl v5.18.2
- Ubuntu 12.04.04,Perl v5.14.2
- VirtualBox 4.2.16r86992
转帖链接: https://forums.virtualbox.org/viewtopic.php?f=2&t=61011
C:\strawberry\perl\bin
和\perl.exe
之间留有空格吗? - mob