Archive :: Any给出了IO错误

时间:2013-03-22 15:01:28

标签: windows perl cygwin cpan

#!/usr/bin/perl
use strict;
use warnings;

my $archive_files = "C:\\Temp\\FREMOTE\\test.zip";
sub extract_archive($$);

extract_archive($archive_files, "C:\\Temp\\FREMOTE\\TEST\\");
extract_archive("C:\\Temp\\FREMOTE\\TEST\\testb.zip",
                "C:\\Temp\\FREMOTE\\TEST\\testb\\");

sub extract_archive($$) { 
    my $archive_file = shift;
    my $extract_dir  = shift;
    if (!  -d "$extract_dir") {
        mkdir $extract_dir;
    }
    use Archive::Any;
    my $archive = Archive::Any->new($archive_file);
    if($archive->extract($extract_dir)) {
        print "Extracted $archive_file into $extract_dir\n";
        undef $archive;
    } else {
        print "Failed to extracted $archive_file into $extract_dir\n";
    }
}

我收到以下错误。我该如何解决?

IO error: write error during copy : Bad file descriptor
 at C:/Perl/site/lib/Archive/Any.pm line 193.
IO error: write error during copy : Bad file descriptor
 at C:/Perl/site/lib/Archive/Any.pm line 193.
IO error: write error during copy : Bad file descriptor
 at C:/Perl/site/lib/Archive/Any.pm line 193.
IO error: write error during copy : Bad file descriptor
 at C:/Perl/site/lib/Archive/Any.pm line 193.

1 个答案:

答案 0 :(得分:0)

我用以下代码测试了它。使用两个已知良好的zip文件,我将第二个zip文件添加到第一个 - 重现我相信你正在做的事情。使用原始代码,我在提取第二个文件时一直收到错误:

Extracted C:\Temp\colorbox-master.zip into C:\Temp\FREMOTE\TEST\<br>
Can't call method "extract" on an undefined value at Perl-1.pl line 19.

与您的错误不同,但使用以下代码修复:

#!/usr/bin/perl
use strict;
use warnings;

my $archive_files = "C:\\Temp\\colorbox-master.zip";

extract_archive($archive_files, "C:\\Temp\\FREMOTE\\TEST\\");
extract_archive("C:\\Temp\\FREMOTE\\TEST\\easybox-v1.3.zip", "C:\\Temp\\FREMOTE\\TEST\\testb\\");

sub extract_archive {
    my $archive_file = shift;
    my $extract_dir  = shift;
    if (!-d "$extract_dir") {
        mkdir $extract_dir;
    }
    use Archive::Any;
    my $archive = Archive::Any->new($archive_file);
    if($archive->extract($extract_dir)) {
        print "Extracted $archive_file into $extract_dir\n";
        undef $archive;
    } else {
        print "Failed to extracted $archive_file into $extract_dir\n";
    }
}

将C:\ Temp \ colorbox-master.zip提取到C:\ Temp \ FREMOTE \ TEST \
将C:\ Temp \ FREMOTE \ TEST \ easybox-v1.3.zip解压缩到C:\ Temp \ FREMOTE \ TEST \ testb \

请注意,我刚刚安装了“Archive :: Any-0.0932”模块(ActiveState Perl),因此我可能有一个不同的(固定)版本。您可能想要检查您的模块是否是最新版本。而且你的zip文件没有被破坏。