首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Perl中捕获BZIP2终止

在Perl中捕获BZIP2终止
EN

Stack Overflow用户
提问于 2013-04-16 00:36:17
回答 2查看 100关注 0票数 1

这是我到目前为止所知道的:

代码语言:javascript
复制
#!/usr/bin/perl

use strict;
use warnings;

use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error);
use File::Find;
use File::Basename;

my $directory = "/usr/www/op1/public/server";
my @list_of_files;

find sub {
        return if -d;
        my $current = basename("$File::Find::name");

        if ($current =~ /\.bz2$/i)
        {
                #print "<$current> is already compressed! Moving along!\n";
                return;
        }

        print "<$current> is being compressed!\n";
        bzip2 $File::Find::name => "$File::Find::name.bz2";

        if (!("$Bzip2Error" eq ""))
        {
                print "\n$Bzip2Error at $File::Find::name\n";
                print "Trying again to compress <$current>\n";
                bzip2 $File::Find::name => "$File::Find::name.bz2" or print "FAILURE 2!!!";
        }
}, "$directory";

基本上,当它决定终止时bzipping:

代码语言:javascript
复制
<bobsagot> is being compressed!
<arthur.bsp.bz2> is already compressed! Moving along!
<reed.bsp.bz2> is already compressed! Moving along!
<bobby.bsp.bz2> is already compressed! Moving along!
<bigjoe.bsp> is being compressed!
Terminated

它会立即从失败的地方恢复并继续运行,但是我没有从$Bzip2Error中打印出错误,所以我感到困惑。如何捕获bzip2失败的事件?

谢谢!

EN

回答 2

Stack Overflow用户

发布于 2013-04-16 21:04:44

你的代码中有没有出现剪切粘贴错误?以"system(“)开头的行不正确。

脚本是否在bzip2调用期间自行终止?

如果你像这样写代码,会发生什么?

代码语言:javascript
复制
if ( ! bzip2 $File::Find::name => "$File::Find::name.bz2")
{
    print "\nBzip Errir is [$Bzip2Error] System Error is [$!] at $File::Find::name\n";
}
票数 0
EN

Stack Overflow用户

发布于 2013-04-29 20:07:34

共享主机将perl执行时间限制为60秒。失去希望:D

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16020330

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档